首页 / PYTHON / Python之数据类型
Python之数据类型
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python之数据类型,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2836字,纯文字阅读大概需要5分钟。
内容图文
![Python之数据类型](/upload/InfoBanner/zyjiaocheng/670/475b8ffb3af44671b0f816c151028da5.jpg)
数据类型
一:简介
有int float bin chr bool等,还有还有容器类list tuple set dict,以及更多的namedtuple,ordereddict等等。
这么我们可以常用的数据类型帮我们更好的处理数据,他们全部都是类,是内置类,里面的有许多方法,节省了我们的时间不用再写直接拿过来用。
没有你适合的?那么就自定义数据类型,就是自定义类喽,创建的对象就是自定义对象。
int() dict()等等都是创建了一个对象。
二:list
l = []
l=list()都是创建空列表
my_list?=?[10,'hello',True,None,[1,2,3],print]可以存放任意数据类型,因为数据外置,但是索引位置都是固定4bytes地址空间。不能超过索引否则报异常import pprint pprint.pprint(dir(list))
显示list所有方法,本质背后调用的list.__dict__拿的list的名称空间里面的所有属性和方法的key。
['__add__',
'__class__',
'__contains__',
'__delattr__',
'__delitem__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__gt__',
'__hash__',
'__iadd__',
'__imul__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__reversed__',
'__rmul__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__',
'append'
'clear',
'copy',
'count',
'extend',
'index',
'insert',
'pop',
'remove',
'reverse',
'sort']
双下的方法是为了高度定制类,看后面没有下划线的方法。直接help(list)
/是python3.8新特性,/左边是位置参数,必须传递。
append(self, object, /)
| Append object to the end of the list.
|
| clear(self, /)
| Remove all items from list.
|
| copy(self, /)
| Return a shallow copy of the list.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| extend(self, iterable, /)
| Extend list by appending elements from the iterable.不是必须是列表,只要是可迭代的即可。
|
| index(self, value, start=0, stop=2147483647, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| insert(self, index, object, /)
| Insert object before index.
|
| pop(self, index=-1, /)#默认弹出的是最后一个,可以指定索引来弹出
| Remove and return item at index (default last).
|
| Raises IndexError if list is empty or index is out of range.
|
| remove(self, value, /)#移除指定元素,只有第一个
| Remove first occurrence of value.
|
| Raises ValueError if the value is not present.
|
| reverse(self, /)
| Reverse *IN PLACE*.
|
| sort(self, /, *, key=None, reverse=False)#默认升序,默认不反转,需要反转就改为True
| Sort the list in ascending order and return None.
|
| The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
| order of two equal elements is maintained).
|
| If a key function is given, apply it once to each list item and sort them,
| ascending or descending, according to their function values.
|
| The reverse flag can be set to sort in descending order.
|
其他就不写了,help()就可以自查,这是需要记忆的,但是这么多总会遗忘,多看看敲敲。
内容总结
以上是互联网集市为您收集整理的Python之数据类型全部内容,希望文章能够帮你解决Python之数据类型所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。