MATH_CONST_VALUE=(3.1415,2.71828)
MATH_CONST_VALUE[1]=2.7
TypeErrorTraceback (most recent call last) <ipython-input-1-b2533e01f223> in <module>() 1 MATH_CONST_VALUE=(3.1415,2.71828) ----> 2 MATH_CONST_VALUE[1]=2.7 TypeError: 'tuple' object does not support item assignment
MATH_CONST_VALUE=([3.1415],[2.71828])
MATH_CONST_VALUE[0][0]=3.14
print MATH_CONST_VALUE
([3.14], [2.71828])
print "AACBBBCAA".replace("BBB","AAA")
AACAAACAA
cmp("beiping","beijing")
1
"China Beijing".find("i")
2
name="Bill gates"
print name.title()
print name.upper()
print name.lower()
Bill Gates BILL GATES bill gates
print " China,Beijing,Chaoyang ".strip()
print " China,Beijing,Chaoyang ".lstrip()
print " China,Beijing,Chaoyang ".rstrip()
China,Beijing,Chaoyang China,Beijing,Chaoyang China,Beijing,Chaoyang
" China,Beijing,Chaoyang ".split(",")
[' China', 'Beijing', 'Chaoyang ']
" China,Beijing,Chaoyang ".split("i")
[' Ch', 'na,Be', 'j', 'ng,Chaoyang ']
mydict={}
k=150717
mydict[`k`]=[99,103,98,102,123,456]
print(mydict[`k`])
k=k+1
print(mydict.get(`k`))
print(mydict[`k`])
[99, 103, 98, 102, 123, 456] None
KeyErrorTraceback (most recent call last) <ipython-input-14-97871591f1e0> in <module>() 5 k=k+1 6 print(mydict.get(`k`)) ----> 7 print(mydict[`k`]) KeyError: '150718'
my_empo_dict={101:['tim','0:444689-202,F:34587349'],102:['Yuri','3424243'],103:['John','0:3243141,H:8925738']}
my_empo_dict[106]=['Mark','3465774']
my_empo_dict.update({107:['Lary','8936274']})
print my_empo_dict
print"Keys:"
print my_empo_dict.keys()
print"Key-Value"
print my_empo_dict.items()
{106: ['Mark', '3465774'], 107: ['Lary', '8936274'], 101: ['tim', '0:444689-202,F:34587349'], 102: ['Yuri', '3424243'], 103: ['John', '0:3243141,H:8925738']} Keys: [106, 107, 101, 102, 103] Key-Value [(106, ['Mark', '3465774']), (107, ['Lary', '8936274']), (101, ['tim', '0:444689-202,F:34587349']), (102, ['Yuri', '3424243']), (103, ['John', '0:3243141,H:8925738'])]
S = {123, 'sed', (10, 'cs'), 43}
W = set("apple")
V = set(('dog','cat','tiger','human'))
print W
print V
set(['a', 'p', 'e', 'l']) set(['tiger', 'dog', 'human', 'cat'])
"BIT" in {123, "BIT", "ok", "test"}
True
tup = (123,"BIT", "ok", "test", 123)
print set(tup)
newtup = tuple(set(tup)-{"test"})
print newtup
set(['test', 'BIT', 123, 'ok']) ('BIT', 123, 'ok')