我a = a[1:] = [2]在一篇文章中找到了作业.我在python3和python2中尝试过它; 这一切都有效,但我不明白它是如何工作的. =这里不像C; C =从右到左进行处理.python如何处理=运算符?
我有以下代码:
import matplotlib.pyplot as plt
x = [i * 2872155 for i in range(1, 11)]
y = [0.219, 0.402, 0.543, 0.646,0.765, 0.880,1.169, 1.358,1.492,1.611]
plt.plot(x, y)
Run Code Online (Sandbox Code Playgroud)
情节是
但我希望 y 标签类似于 0.2s、0.4s、0.6s。我怎样才能做到这一点?
我曾经认为这 /proc/self和/proc/$$bash 终端是一样的,但现在我发现它们是不同的。
我知道$$意味着当前进程的 pid,并且/proc/self是当前正在运行的进程,它应该是 bash 终端。为什么它们不同?
root@VM-73-203-debian:~# echo $$
24415
root@VM-73-203-debian:~# ls -l /proc/self
lrwxrwxrwx 1 root root 0 Nov 22 2018 /proc/self -> 24465
root@VM-73-203-debian:~# ls -l /proc/$$
total 0
dr-xr-xr-x 2 root root 0 May 29 16:23 attr
...
Run Code Online (Sandbox Code Playgroud) 我有一些代码synchronized用来保护我递增的计数器count++。
我希望我正确地保护了代码部分,因此得到2_0000_0000了结果,因为count在多次执行它之后,这将是正确的值,多线程。
但是,在运行代码时,我得到一个低于预期的值2_0000_0000,就好像我synchronized没有正确保护代码部分一样。
为什么会这样,我做错了什么?
public class Test {
private static Integer count = 0;
private static void add10K() {
long idx = 0;
while (idx++ < 1_0000_0000) {
synchronized (count){
count += 1;
}
}
}
public static long calc() {
Thread th1 = new Thread(Test::add10K);
Thread th2 = new Thread(Test::add10K);
th1.start();
th2.start();
try {
th1.join();
th2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
return count;
}
public …Run Code Online (Sandbox Code Playgroud) python ×2
atomic ×1
bash ×1
java ×1
linux ×1
matplotlib ×1
python-2.7 ×1
python-3.x ×1
shell ×1
synchronized ×1