-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
69 lines (68 loc) · 1.4 KB
/
data.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
# -*- coding:utf-8 -*-
a = 1
b = "1234"
c = 123.456
d = [1, '1234', 'abc']
e = (1,)
f = {'name': 'zhang', 'age': 30}
g = set(f)
print(a, type(a))
print(b, type(b))
print(c, type(c))
print(d, type(d))
print(e, type(e))
print(f, type(f))
print(g, type(g))
print("-----------------")
print(a, id(a))
a = 2
print(a, id(a))
# list、set、dict:是不可哈希的
# f = {d: 123}
# int、float、str、tuple:是可以哈希的
print("a __hash__:", a.__hash__)
print("b __hash__:", b.__hash__)
print("c __hash__:", c.__hash__)
print("d __hash__:", d.__hash__)
print("e __hash__:", e.__hash__)
print("f __hash__:", f.__hash__)
print("g __hash__:", g.__hash__)
print("-----------------")
# list set , tuple str, dict: 可迭代对象
# int float: 不是可迭代对象
#print(iter(a))
print(iter(e))
print(dir(f))
print("-----------------")
print(dir(a))
print("-----------------")
# str 常用函数
a = "123:456"
print(a.split(":"))
print(a.find('4'))
print(a.replace("123", 'abc'))
print(a[1:3])
print("-----------------")
# list 常用方法
d.append("efg")
print(d)
d.pop(0)
print(d)
d.extend("12")
print(d)
d.remove("efg")
print(d)
print("-----------------")
# dict 常用方法
print(f.get("name", None))
print(f['name'])
f.setdefault("address", "shanghai")
print f
f['address'] = "beijing"
print f
f.pop('address')
print f
# 3,x 去掉了 dict.items() 方法
print(f.items())
print(f.iteritems())
print(f.iterkeys(), f.itervalues())