forked from xiyouMc/PythonGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python_Guide.py
114 lines (94 loc) · 1.54 KB
/
Python_Guide.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import json
data = {'b':123,'c':456,'a':'789'}
d1 = json.dumps(data,sort_keys=True,indent=4);
print d1
print data
print '''line1
line2
line3'''
print 3>2
print True and False
print not True
age = 17
if age >18:
print 'adult'
else:
print 'teenager'
PI=1111
print PI
print 10.0/3
#list
classmates=['Mark','Bob','Tracy']
print classmates
# list len
print len(classmates)
print classmates[0]
# last
print classmates[-1]
classmates.append("Adam")
print classmates
classmates.insert(1,'aaaa')
print classmates
classmates.pop();
print classmates
#tuple Not Change.diff list:not append insert
noChange=('aa','bb')
print noChange
t = (1,)
print t
L = [
['Apple', 'Google', 'Microsoft'],
['Java', 'Python', 'Ruby', 'PHP'],
['Adam', 'Bart', 'Lisa']
]
print L[0][0]
print L[1][1]
print L[2][2]
#if...elif
age = 3
if age >= 18:
print('adult')
elif age >= 6:
print('teenager')
else:
print('kid')
s = '123'
birth = int(s)
if birth<200:
print 'AAA'
else:
print 'BBB'
#for in
names=['Mark','Bob','Tracy']
for name in names:
print name
# 1+2....+1000 range
sum=0
for x in range(1000):
sum = sum + x
print sum
n = 0
while n < len(L):
i = 0
while i < len(L[n]):
print L[n][i]
i = 1+i
n = 1+n
#dict->Map
d = {'Mark':95,'Bob':75,'Tracy':85}
print d['Mark']
d.pop('Tracy')
print d
print d.get('Bob')
print d.get('Tracy',-1)
#set
s = set([1,2,3])
print s
s.add(4)
print s
s.remove(4)
print s
print abs(-100),max(1,2,3,47,1),min(1,2,3,40,4,0)
print int('123')
aa = abs
print aa(-1),hex(255),hex(1000)