1
- type (42 )
1
+ #number
2
+
3
+ print 2 ** 100
4
+ print 1.5 * 4
5
+ print len (str (2 ** 100000 ))
6
+
7
+ 3.1415 * 2
8
+ print (3.1415 * 2 )
9
+ import math
10
+ print math .pi
11
+ print math .sqrt (4 )
12
+
13
+ import random
14
+ print random .random ()
15
+ print random .choice ([1 , 2 , 3 , 4 ])
16
+
17
+ S = 'Spam'
18
+ print len (S )
19
+ print S [0 ]
20
+ print S [3 ]
21
+ print S [- 1 ]
22
+ print S [- 2 ]
23
+ print S [1 :3 ]
24
+ print S [:]
25
+ print S + 'xyz'
26
+ print S * 8
27
+
28
+ #str only support over rewrite
29
+ S = 'z' + S [1 :]
30
+ print S
31
+ strList = "aaa,bbb,cccc,dd"
32
+ list = strList .split (',' )
33
+ print list
34
+ print list [1 :]
35
+
36
+ #str method
37
+ S = S .upper ()
38
+ print S
39
+ isAl = S .isalpha ()
40
+ print isAl
41
+ isDigit = S .isdigit ();
42
+ print isDigit
43
+ line = 'aaa,bbb,ccc,dd\n '
44
+ line = line .rstrip ()
45
+ print line * 2
46
+
47
+ #str format
48
+ str = '%s,eggs,and %s' % ('cluo' ,'chunling' )
49
+ print str
50
+ str = '{0} eggs , and {1} chicken' .format ('1' ,'3' )
51
+ print str
52
+
53
+ #check method of object
54
+ methodlist = dir (str )
55
+ print methodlist
56
+ print __name__
57
+ doc = help (str .replace )
58
+
59
+ #break line """" <pre></pre>
60
+ msg = """ cluo
61
+ cluo1
62
+ cluo2
63
+ cluo3
64
+ cluo4"""
65
+
66
+ fileObj = open ('cluo' ,'w' )
67
+ fileObj .write (msg )
68
+ fileObj = open ('cluo' ,'r' )
69
+ arr = []
70
+ for eachLine in fileObj :
71
+ arr .append (eachLine )
72
+ str = 'a' .join (arr )
73
+ fileObj = open ('cluo' ,'w' )
74
+ fileObj .write (str )
75
+
76
+ #regex
77
+ import re
78
+ match = re .match ('Hello\s+(.*)world' ,'Hello python world' )
79
+ inner = match .group (1 );
80
+ print inner
81
+
82
+ match = re .match ('/(.*)/(.*)/(.*)' ,'/usr/home/bbq' )
83
+ groups = match .groups ()
84
+ print groups
85
+ print groups [0 :]
86
+
87
+
88
+ #list
89
+ l = [123 , 'spam' , 1.23 ]
90
+ s = 'string'
91
+ print len (l )
92
+ print len (s )
93
+ print l [- 1 ]
94
+ print l [0 :- 1 ]
95
+ print l + [4 , 5 , 6 ]
96
+
97
+ 132
98
+
99
+ #list method
100
+ l .append ('NI' )
101
+ print l
102
+
103
+ l .sort ();
104
+ print l
105
+ l .reverse ();
106
+ print l
107
+
108
+ m = [
109
+ [1 , 2 , 3 ],
110
+ [4 , 5 , 6 ],
111
+ [7 , 8 ,9 ]
112
+ ]
113
+ print m
114
+ print m [1 ];
115
+ print m [1 ][0 ]
116
+
117
+ #list parse method (pre result_function)
118
+ cols2 = [row [1 ] for row in m ]
119
+ print cols2 ;
120
+
121
+ cols3 = [row [1 ] + 1 for row in m ]
122
+ print cols3
123
+
124
+ #list parse method (add filter_function) map
125
+ cols4 = [row [1 ] + 1 for row in m if row [1 ] % 2 == 0 ]
126
+ print cols4
127
+
128
+ #list numpy filter
129
+ diag = [m [i ][i ] for i in [0 , 1 ,2 ]]
130
+ print diag
131
+
132
+ doubles = [c * 2 for c in 'spam' ]
133
+ print doubles
134
+
135
+ G = (sum (row ) for row in m )
136
+ print G
137
+ print next (G )
138
+ print next (G )
139
+ print next (G )
140
+
141
+ list = [ord (x ) for x in 'spaam' ]
142
+ print list
143
+ list = {ord (x ) for x in 'spaam' }
144
+ print list
145
+ list = {x :ord (x ) for x in 'spaam' }
146
+ print list
147
+
148
+ D = {'food' :'spam' , 'quantity' :4 , 'color' :'pink' }
149
+ print D ['food' ]
150
+ print D ['quantity' ] + 1
151
+
152
+ D = {}
153
+ D ['name' ] = 'Bob'
154
+ D ['job' ] = 'dev'
155
+ D ['age' ] = 40
156
+ print D
157
+
158
+ rec = {
159
+ 'name' :{'first' : 'Bob' , 'last' : 'Smith' },
160
+ 'job' :['dev' , 'mgr' ],
161
+ 'age' : 40.5
162
+ }
163
+
164
+ print rec ['name' ]
165
+ print rec ['name' ]['last' ]
166
+ print rec ['job' ][- 1 ]
167
+ rec ['job' ].append ('janitor' )
168
+ print rec
169
+
170
+ print D .keys ()
171
+ list = D .keys ()
172
+ list .sort () #return none????
173
+ print list
174
+
175
+ #auto sorted
176
+ D = {'b' :2 ,'a' :1 ,'c' :3 }
177
+ for item in D :
178
+ print (item ,'=>' ,D [item ])
179
+ for item in sorted (D ): #sorted key
180
+ print (item ,'=>' ,D [item ])
0 commit comments