Repository navigation
Expand file tree
/
Copy pathbasic_grammer.py
More file actions
executable file
·83 lines (62 loc) · 1.48 KB
/
Copy pathbasic_grammer.py
File metadata and controls
executable file
·83 lines (62 loc) · 1.48 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
77
78
79
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Date : 2018-01-16 20:44:17
# @Author : MetalSeed (mc.gaofei@gmail.com)
# @Link : ------------------
# @Version : $Id$
###### ######
###### keyword ######
###### ######
## print
print('a = %d b = %.2f s = %s' % (10, 0.1111,'string'))
print('a =' , 1, 'b = ', 2, 'c = ', 3)
## condition
age = 20
if age >= 10:
pass
elif age >= 21:
pass
else:
pass
## loop
n = 3
for x in range(1, n):
# pass
print(x)
while n > 10:
pass
## list tuple tict set
# List[1], len(List), List.sort()
List = [1, 2, 3, 4]
Tuple = (1, 2, 3, 4)
# if 'a' in Dict, d.pop('a')
Dict = {'a':1, 'b':2, 'c':3}
# Set.add(4), Set.remove(4), s1 | s2, s1 & s2
Set = set([1, 1, 2, 2, 3])
###### ######
###### function ######
###### ######
def demo(a, b):
return a, b # return a tuple
def f1(a, b, c=0, *args, **kw):
print('a =', a, 'b =', b, 'c =', c, 'args =', args, 'kw =', kw)
return
list0 = [3, 3, 3]
dict0 = {'d':99, 'x':'#'}
f1(1, 2, 3, *list0, **dict0)
tuple0 = (1, 2, 3, 4, 5)
f1(*tuple0, **dict0)
###### ######
###### IO ######
###### ######
## file io
# f.read(), f.read(size), f.readline(), f.readlines()
name = '/Users/MetalSeed/Documents/CodeBox/Python/foo/read.txt'
with open(name, 'r') as f:
for line in f.readlines():
pass
# print(line.strip())
# open(name, 'w'), open(name, 'a')
name = '/Users/MetalSeed/Documents/CodeBox/Python/foo/write.txt'
with open(name, 'w') as f:
f.write('a = 0\n')