-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_random_notes
More file actions
76 lines (51 loc) · 1.6 KB
/
python_random_notes
File metadata and controls
76 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
1.variables must stary with a letter or underscore_
CASE sensitive!!
2. ** power
% remainder
/ 不是整数除法,就是正常的除 (in python 3) python2 和 c++一样还是整数除法
1+1.0 // 2.0 auto do the float convert for you
// --- Interger Division
5//3 #1
10//3 #3 (always round down)
1/2 #0.5 python always get float
2**3 #8
49**0.5 #7
13%2 #1
3. naming_conventions
most variables should be lower case,
CAPITAL_NAME usually is constants
UpperCamelCase : refer to a class
"dunder" for double underscore ***
4.string format
interpolate #插入
f-strings (python 3.6+)
x = 10
formatted = f"I told you {x} times!" #不可以忘了这个f!
#you can also do math in the {}
# in python 2 .format() --play ground only support it
print("the {} is ).format(sth)
first = "Colt"
last = "Steele"
formatted = "First Name: {}, Last Name: {}". format(first, last) #可以直接在string 后加
5.is vs ==
is check with the memory and == checks value
is--checking equality
a = 1
a == 1 #True
a is 1 #True
a = [1,2,3]
b = [1,2,3]
a == b #True
a is b #Flase, they are different objects
c = b
b is c #True, b and c are pointing to the same stuff
a = 13
b = 13
a == b #True
a is b #True
6. use # for comments in python
''' for python multiple line comments
7. python use indent to distinguish block, which is 4 spaces, it is better to use space than tab, to avoid difference between different editors
8. python 里的print() 有自动换行功效
9. for installing package in jupyter
https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/