>>> type ([1,2,3,4,5,6]) //检测类型(列表)
<class 'list'>
>>> (1,2,3,4)[0] //索引
1
>>>(1,2,3)+(4,5,6) //元组拼接
(1,2,3,4,5,6)
>>>(1,2,3) *3 //这个就很好理解了 几个元祖
(1,2,3,1,2,3,1,2,3)
>>> type (1,2,3) // 检测类型(元组)
<class 'tuple'>
>>> type(1) // 检测类型(整数)
<class 'int'>
>>> type((1)) //因为系统以为你里面是计算方式的() 例如 type((1+1)*1)
<class 'int'>
>>> type((1,)) //加个,避免以上问题
<class 'tuple'>
>>>type([1]) //正常检测
<class 'list'>
>>> 3 in [1,2,3,4,5,6] // in 是否存在 返回值为bool
True
>>> 10 in [1,2,3,5,7]
False
>>> 3 not in [1,2,3,4,5,6] // not in 是否不存在
False
>>> len([1,2,3,4,5,6]) //len 长度
6
>>>len('hello word')
11
>>> max([1,2,3,4,5,6]) //max 最大值
6
>>>min([1,2,3,4,5,6]) //min 最小值
1
>>>max('hello world') // max是公用的 都可以用 如果是字母的话 则按照字母排序 ***但是注意 不能混写 数字和字母的混写
'w'
>> min(''hello world') // ‘ ’优先
' '
>>>min(''helloworld')
'd'
集合 {}
>>> type ({1,2,3,4,5,6})
<class 'set'>
>>> {1,2,3,4,5,6}[0] //(集合是无序的,所以没有)
报错
>>> {1,1,2,2,3,3,4,4} //集合的特性:不重复
{1,2,3}
>>> len ({1,2,3})
3
>>> 1in {1,2,3}
True
>>> {1,2,3,4,5,6} - {3,4} //求两个集合的差集
{1,2,5,6}
>>> {1,2,3,4,5,6} & {3,4} //交集
{3,4}
>>> {1,2,3,4,5,6} | {3,4,7} //并集
{1,2,3,4,5,6,7}
子集
>>> type({1:2,1:3})
<class 'dict'>
网友评论