格式化字符串--原始字符串--列表--字典---的一些操作

1 >>> s='hello'
2 >>> s='so %s a day'
3 >>> print s % 'beautiful'    格式化字符串  %s来作为一个变量站位
4 so beautiful a day
1 >>> import string
2 >>> string.atoi('10')+1   数字转换为字符串
3 11
4 >>> str(10)+'1'
5 '101'
1 >>> import os
2 >>> os.listdir(r'c:EFI')
3 ['abc', 'Boot', 'Microsoft']    r''表示原始字符串 不在表示转义
>>> list=['a','b','c',1,2]   列表的一些操作
>>> list.append('A')
>>> list
['a', 'b', 'c', 1, 2, 'A']
>>> list.count('a')
1
>>> list.extend(list)
>>> list
['a', 'b', 'c', 1, 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
>>> list.index(1)
3
>>> list.insert(4,'B')
>>> list
['a', 'b', 'c', 1, 'B', 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
>>> list.pop(2)
'c'
>>> list
['a', 'b', 1, 'B', 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
>>> list.remove('a')
>>> list
['b', 1, 'B', 2, 'A', 'a', 'b', 'c', 1, 2, 'A']
>>> list.reverse()
>>> list
['A', 2, 1, 'c', 'b', 'a', 'A', 2, 'B', 1, 'b']
>>> list.sort()
>>> list
[1, 1, 2, 2, 'A', 'A', 'B', 'a', 'b', 'b', 'c']
 1 >>> dic={'apple':'red','pen':'balck'}   字典的一些操作
 2 >>> dic
 3 {'pen': 'balck', 'apple': 'red'}
 4 >>> dic.copy
 5 <built-in method copy of dict object at 0x0000000002C77488>
 6 >>> dic.copy()
 7 {'pen': 'balck', 'apple': 'red'}
 8 >>> dic.get('apple')
 9 'red'
10 >>> dic.has_key('banna')
11 False
12 >>> dic.items()
13 [('pen', 'balck'), ('apple', 'red')]
14 >>> dic.keys()
15 ['pen', 'apple']
16 >>> dic.pop('apple')
17 'red'
18 >>> dic
19 {'pen': 'balck'}
20 >>> dic.update({'apple':'red'})
21 >>> dic
22 {'pen': 'balck', 'apple': 'red'}
23 >>> dic.update({'apple':1})
24 >>> dic
25 {'pen': 'balck', 'apple': 1}
26 >>> dic.values()
27 ['balck', 1]
原文地址:https://www.cnblogs.com/caojunjie/p/6742728.html