Python(三)数据类型
程序员文章站
2022-06-08 11:06:03
...
Python数据类型
字符串 str
整型 int
浮点型 float(e记法)
bool
type(v)函数
isinstance(v, str/int/float/...)
列表
>>> member = [1, 2, 3, 4, 5]
>>> member
[1, 2, 3, 4, 5]
>>> len(member)
5
>>> member.insert(1, 0)
>>> member
[1, 0, 2, 3, 4, 5]
>>> print(member)
[1, 0, 2, 3, 4, 5]
>>> member.append(10)
>>> member
[1, 0, 2, 3, 4, 5, 10]
>>> member1 = [11, 22, 33]
>>> member.extend(member1)
>>> member
[1, 0, 2, 3, 4, 5, 10, 11, 22, 33]
列表member,操作len(长度)\insert(插入)\append(结尾追加)\extend(一个列表扩充另一个列表进来)
>>> member.remove(0) //直接删除元素
>>> member
[1, 2, 3, 4, 5, 10, 11, 22, 33]
//del语句
>>> member.insert(1, 0)
>>> member
[1, 0, 2, 3, 4, 5, 10, 11, 22, 33]
>>> del member[1]
>>> member
[1, 2, 3, 4, 5, 10, 11, 22, 33]
//pop()弹出末尾元素 pop(index)弹出制定下标的元素
>>> member.pop()
33
//列表分片
>>>member[1:3]
[2, 3]
//查看一个对象的方法和属性 dir(object)
//从某个下标开始查找元素的下标,obj.index(ele, [from], [end])
//列表拷贝
list1 = [1, 2, 3]
list2 = list1[:] 列表拷贝
list3 = list1 引用拷贝
字符串 str
整型 int
浮点型 float(e记法)
bool
type(v)函数
isinstance(v, str/int/float/...)
列表
>>> member = [1, 2, 3, 4, 5]
>>> member
[1, 2, 3, 4, 5]
>>> len(member)
5
>>> member.insert(1, 0)
>>> member
[1, 0, 2, 3, 4, 5]
>>> print(member)
[1, 0, 2, 3, 4, 5]
>>> member.append(10)
>>> member
[1, 0, 2, 3, 4, 5, 10]
>>> member1 = [11, 22, 33]
>>> member.extend(member1)
>>> member
[1, 0, 2, 3, 4, 5, 10, 11, 22, 33]
列表member,操作len(长度)\insert(插入)\append(结尾追加)\extend(一个列表扩充另一个列表进来)
>>> member.remove(0) //直接删除元素
>>> member
[1, 2, 3, 4, 5, 10, 11, 22, 33]
//del语句
>>> member.insert(1, 0)
>>> member
[1, 0, 2, 3, 4, 5, 10, 11, 22, 33]
>>> del member[1]
>>> member
[1, 2, 3, 4, 5, 10, 11, 22, 33]
//pop()弹出末尾元素 pop(index)弹出制定下标的元素
>>> member.pop()
33
//列表分片
>>>member[1:3]
[2, 3]
//查看一个对象的方法和属性 dir(object)
//从某个下标开始查找元素的下标,obj.index(ele, [from], [end])
//列表拷贝
list1 = [1, 2, 3]
list2 = list1[:] 列表拷贝
list3 = list1 引用拷贝
上一篇: Python(十)文件存储
下一篇: 古代书信都是怎么送的 仅仅靠的是马车吗