标签:pop 字符串 diff insert 获取值 ini 特定 union ascii
列表常见方法:
>>> a
[1, 2, 3, 4]
>>> a.append(0)
>>> a
[1, 2, 3, 4, 0]
>>>
>>> a
[1, 2, 3, 4, 0]
>>>
>>> a.insert(0,5)
>>> a
[5, 1, 2, 3, 4, 0]
>>>
>>> a
[5, 1, 2, 3, 4, 0]=
>>> a.clear()
>>> a
[]
>>> a
[]
>>> a=[1,2,3,4,5]
>>> a
[1, 2, 3, 4, 5]
>>> a.remove(5)
>>> a
[1, 2, 3, 4]
>>>
>>> a
[1, 2, 3, 4]
>>>
>>> a.pop()
4
>>> a.pop()
3
>>> a
[1, 2]
>>> a=[1,2,3,4,5]
>>> a
[1, 2, 3, 4, 5]
>>> a.index(3)
2
>>>
>>> a
[1, 2, 3, 4, 5]
>>> a.reverse()
>>> a
[5, 4, 3, 2, 1]
>>>
>>> a
[5, 4, 3, 2, 1]
>>> a.sort()
>>> a
[1, 2, 3, 4, 5]
>>>
>>> a.copy()
[1, 2, 3, 4, 5]
>>> a
[1, 2, 3, 4, 5]
>>>
>>> b=[6,7,8,9]
>>> a
[1, 2, 3, 4, 5]
>>> b
[6, 7, 8, 9]
>>> a.extend(b)
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
集合(无序并且不能重复)
集合常见方法:
>>> a={1,2,3,4,5}
>>> a
{1, 2, 3, 4, 5}
>>> a.add(66)
>>> a
{1, 2, 3, 4, 5, 66}
>>>
>>> a
{1, 2, 3, 4, 5, 66}
>>> a.clear()
>>> a
set()
>>>
>>>
>>> a={11,22,33,44}
>>> a
{33, 11, 44, 22}
>>> a.copy()
{33, 11, 44, 22}
>>> a
{33, 11, 44, 22}
>>> a
{33, 11, 44, 22}
>>> a.pop()
33
>>> a.pop()
11
>>> a
{44, 22}
>>>
>>> a
{44, 22}
>>> a.remove(44)
>>> a
{22}
>>>
>>> a={11,22,33,44}
>>> a
{33, 11, 44, 22}
>>> b={22,33,44,55}
>>> b
{33, 44, 22, 55}
>>> a.intersection(b)
{33, 44, 22}
>>>
>>> a
{33, 11, 44, 22}
>>> b
{33, 44, 22, 55}
>>> a.difference(b)
{11}
>>>
>>> a
{33, 11, 44, 22}
>>> b
{33, 44, 22, 55}
>>> a.union(b)
{33, 11, 44, 22, 55}
>>>
元组:一系列固定的值(不可变数据类型)
注意:在python中,如果只有一个元素,并且该元素是一个数字,则需要加上一个逗号来表示该变量时元组而不是数字
元组常见方法:
>>> a=[1,1,1,1,1,2,3,4]
>>> a.count(1)
5
>>>
>>> a
[1, 1, 1, 1, 1, 2, 3, 4]
>>> a.index(3)
字典是以键值对存在的,每个键对应一个唯一的值。键必须是字符串
None 表示没有
获取key对应的值,使用如下两种方式:
>>> a={‘tiancai‘:‘diyibu‘,‘queshi‘:‘zhiniaoku‘}
>>> a
{‘tiancai‘: ‘diyibu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a["tiancai"]
‘diyibu‘
>>> a["queshi"]
‘zhiniaoku‘
>>>
字典常见方法:
>>>
>>> a
{‘tiancai‘: ‘diyibu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a.clear()
>>> a
{}
>>>
>>> a
{‘tiancai‘: ‘diyibu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a.copy()
{‘tiancai‘: ‘diyibu‘, ‘queshi‘: ‘zhiniaoku‘}
>>>
>>> a
{‘tiancai‘: ‘diyibu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a.pop("tiancai")
‘diyibu‘
>>> a
{‘queshi‘: ‘zhiniaoku‘}
>>>
>>> a={‘tiancai‘:‘diyibu‘,‘queshi‘:‘zhiniaoku‘}
>>> a.popitem()
(‘queshi‘, ‘zhiniaoku‘)
>>> a
{‘tiancai‘: ‘diyibu‘}
>>>
>>> a={‘tiancai‘:‘diyobu‘,‘queshi‘:‘zhiniaoku‘}
>>> a
{‘tiancai‘: ‘diyobu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a.keys()
dict_keys([‘tiancai‘, ‘queshi‘])
>>>
>>> a
{‘tiancai‘: ‘diyobu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a.values()
dict_values([‘diyobu‘, ‘zhiniaoku‘])
>>>
>>> a
{‘tiancai‘: ‘diyobu‘, ‘queshi‘: ‘zhiniaoku‘}
>>> a.items()
dict_items([(‘tiancai‘, ‘diyobu‘), (‘queshi‘, ‘zhiniaoku‘)])
>>>
标签:pop 字符串 diff insert 获取值 ini 特定 union ascii
原文地址:https://www.cnblogs.com/yxh6666/p/11520816.html