-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.1.py
131 lines (98 loc) · 1.92 KB
/
demo.1.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
__author__ = 'admin'
def hello():
"this is a dodument"
return 'hello world';
print hello()
name = 'cluo'
sex = 'boy'
str = 'python'
print str[0]
print str[-1]
print str[1:-1]
print str[:3]
str = str + name + sex
print str
print str * 2
print '_' * 20
print str + '\n' + str
aList = [1, 2, 3, 4]
aTuple = (1, 2, 3, 3)
print aList[0]
print aList[:3]
print aTuple[:2]
print aTuple[:-1]
print aTuple[-1]
aDict = {'HOST': '19851129'}
aDict['port'] = 80
print aDict
print aDict['HOST']
x = 2
if x < 0:
print 'less than 0'
elif x > 0:
print 'more than 0'
else:
print 'eq 0'
while x > 0:
print 'x%d ' % (x)
x -= 1
ret = ""
for item in ['hello', 'world', 'come', 'on']:
ret += item
print ret
ret = ""
for item in ['hello', 'world', 'come', 'on']:
ret += item
print ret,
for eachNum in range(4):
print eachNum
who = 'knights'
what = 'ni!!'
print 'we are the %s say %s' % (who, (what + ' ') * 4)
foo = 'abc'
for c in foo:
print c
foo = 'abc'
for c in foo:
print c,
foo = 'abc'
for i in range(len(foo)):
print foo[i], '(%d)' % i
for i, ch in enumerate(foo):
print ch, '(%d)' % (i)
squared = [x ** 2 for x in range(4)]
for i in squared:
print i
sqdEvents = [x ** 2 for x in range(8) if not x % 2]
for i in sqdEvents:
print i
filename = raw_input('what is cluo?')
fobj = open('/Users/admin/cluo.txt', 'r')
for eachLine in fobj:
print eachLine,
fobj.close()
# try:
# filename = raw_input('what is cluo?')
# fobj = open('/Users/admin/cluo.txt1', 'r')
# for eachLine in fobj:
# print eachLine,
# fobj.close()
# except IOError,e:
# print 'file open error:',e
def make_love(x,y):
"aa bb cc"
return (x + y)
def default_argument_test\
(x=1,y=2):
"aa bb cc"
return (x + y)
print default_argument_test();print make_love(1,2);
x = y = z = 2
print x
#x, y, z = 1, 2, 'a string'
#print x,y,z
x = 3.14
y = x
y += 1
print x
print y