-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
29 lines (22 loc) · 776 Bytes
/
list.py
File metadata and controls
29 lines (22 loc) · 776 Bytes
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
import os
# list 列表生成式
classmates = ['Michael', 'Bob', 'Tracy']
classmates.append('Admin')
classmates.insert(2, 'Jack')
# classmates.pop()
print(classmates)
print('classmates length : %d' % len(classmates))
print('classmates length :', len(classmates))
# tuple 元组
tupleList = ('Michael', 'Bob', 'Tracy')
print('tupleList length : %d' % len(tupleList))
print([x * x for x in range(1, 11)])
print([x * x for x in range(1, 11) if x % 2 == 0])
print([m + n for m in 'ABC' for n in 'XYZ'])
print([d for d in os.listdir('.')])
L = ['Hello', 'World', 'IBM', 'Apple']
print([x.lower() for x in L])
print([x if x % 2 == 0 else -x for x in range(1, 11)])
L1 = ['Hello', 'World', 18, 'Apple', None]
L2 = [x.lower() for x in L1 if isinstance(x, str)]
print('L2', L2)