forked from Xu-Guo/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice.py
More file actions
45 lines (32 loc) · 1.03 KB
/
Copy pathslice.py
File metadata and controls
45 lines (32 loc) · 1.03 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
print "this is **********slice.py******************"
# this is traditional loops
s = ["sdf", "user1", "biingpang", "shelloc"]
i = 0
while i < 3:
print s[i]
i = i + 1
print
print "s[0:2] is:"
print s[0:2]
print 'space'[1:2]
print 'asdfuierer'[-3:]
print (1, 2, 3, 4, 'abc')[-2:]
print
print '#############################print key###############################33'
dict = {"key1": "val1", "key2": "val2", "key3": "val3"}
for key in dict:
print dict[key], key
print '#############################print value###############################33'
for value in dict.itervalues():
print value
print '#############################print key value###############################33'
for k, v in dict.iteritems():
print k, v
print range(1,10)
print [x * x for x in range(1, 10) if x % 2 == 0]
kandv = [k + '+' + v for k, v in dict.iteritems()]
print kandv
L = ['Hello', 'World', 18, 'Apple', None]
print [str(s).lower() for s in L]
# you can add charge after loop. operation before loop.
print [s.lower() for s in L if isinstance(s, str)]