Python数据类型详解(二)列表


Posted in Python onMay 08, 2016

一.基本数据类型

整数:int

字符串:str(注:\t等于一个tab键)

布尔值: bool

列表:list (元素的集合)

列表用[]

元祖:tuple

元祖用()

字典:dict

注:所有的数据类型都存在想对应的类列里

二.列表所有数据类型:

基本操作:

索引,切片,追加,删除,长度,切片,循环,包含

list

class list(object):
  """
  list() -> new empty list
  list(iterable) -> new list initialized from iterable's items
  """
  def append(self, p_object): # real signature unknown; restored from __doc__
    """ L.append(object) -> None -- append object to end """
    (L.append(对象)- >——没有一个对象附加到结束)
    pass

  def clear(self): # real signature unknown; restored from __doc__
    """ L.clear() -> None -- remove all items from L """
    (L.clear()- >没有,把所有项目从L)
    pass

  def copy(self): # real signature unknown; restored from __doc__
    """ L.copy() -> list -- a shallow copy of L """
    (L.copy()- >列表- L的浅拷贝)
    return []

  def count(self, value): # real signature unknown; restored from __doc__
    """ L.count(value) -> integer -- return number of occurrences of value """
    (L.count(价值)- >整数,返回值的出现次数)
    return 0

  def extend(self, iterable): # real signature unknown; restored from __doc__
    """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """
    (L.extend(iterable)- >没有——从iterable扩展列表通过添加元)
    pass

  def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
    """
    L.index(value, [start, [stop]]) -> integer -- return first index of value.
    Raises ValueError if the value is not present.
    (l指数(价值,[开始,[不要]])- >整数,返回第一索引值。提出了ValueError如果不存在的价值。)
    """
    return 0

  def insert(self, index, p_object): # real signature unknown; restored from __doc__
    """ L.insert(index, object) -- insert object before index """
    (l插入(指数(对象)——前插入对象索引)
    pass

  def pop(self, index=None): # real signature unknown; restored from __doc__
    """
    L.pop([index]) -> item -- remove and return item at index (default last).
    Raises IndexError if list is empty or index is out of range.
    (L.pop((指数))- >项目——删除并返回项指数(默认)。提出了IndexError如果列表为空或索引的范围。)
    """
    pass

  def remove(self, value): # real signature unknown; restored from __doc__
    """
    L.remove(value) -> None -- remove first occurrence of value.
    Raises ValueError if the value is not present.
    """
    (L.remove(价值)- >没有,删除第一次出现的值。提出了ValueError如果不存在的价值。)
    pass

  def reverse(self): # real signature unknown; restored from __doc__
    """ L.reverse() -- reverse *IN PLACE* """
    pass

  def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__
    """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
    pass

  def __add__(self, *args, **kwargs): # real signature unknown
    """ Return self+value. """
    pass

  def __contains__(self, *args, **kwargs): # real signature unknown
    """ Return key in self. """
    pass

  def __delitem__(self, *args, **kwargs): # real signature unknown
    """ Delete self[key]. """
    pass

  def __eq__(self, *args, **kwargs): # real signature unknown
    """ Return self==value. """
    pass

  def __getattribute__(self, *args, **kwargs): # real signature unknown
    """ Return getattr(self, name). """
    pass

  def __getitem__(self, y): # real signature unknown; restored from __doc__
    """ x.__getitem__(y) <==> x[y] """
    pass

  def __ge__(self, *args, **kwargs): # real signature unknown
    """ Return self>=value. """
    pass

  def __gt__(self, *args, **kwargs): # real signature unknown
    """ Return self>value. """
    pass

  def __iadd__(self, *args, **kwargs): # real signature unknown
    """ Implement self+=value. """
    pass

  def __imul__(self, *args, **kwargs): # real signature unknown
    """ Implement self*=value. """
    pass

  def __init__(self, seq=()): # known special case of list.__init__
    """
    list() -> new empty list
    list(iterable) -> new list initialized from iterable's items
    # (copied from class doc)
    """
    pass

  def __iter__(self, *args, **kwargs): # real signature unknown
    """ Implement iter(self). """
    pass

  def __len__(self, *args, **kwargs): # real signature unknown
    """ Return len(self). """
    pass

  def __le__(self, *args, **kwargs): # real signature unknown
    """ Return self<=value. """
    pass

  def __lt__(self, *args, **kwargs): # real signature unknown
    """ Return self<value. """
    pass

  def __mul__(self, *args, **kwargs): # real signature unknown
    """ Return self*value.n """
    pass

  @staticmethod # known case of __new__
  def __new__(*args, **kwargs): # real signature unknown
    """ Create and return a new object. See help(type) for accurate signature. """
    pass

  def __ne__(self, *args, **kwargs): # real signature unknown
    """ Return self!=value. """
    pass

  def __repr__(self, *args, **kwargs): # real signature unknown
    """ Return repr(self). """
    pass

  def __reversed__(self): # real signature unknown; restored from __doc__
    """ L.__reversed__() -- return a reverse iterator over the list """
    pass

  def __rmul__(self, *args, **kwargs): # real signature unknown
    """ Return self*value. """
    pass

  def __setitem__(self, *args, **kwargs): # real signature unknown
    """ Set self[key] to value. """
    pass

  def __sizeof__(self): # real signature unknown; restored from __doc__
    """ L.__sizeof__() -- size of L in memory, in bytes """
    pass

  __hash__ = None

三.所有列表数据类型举例

#!/usr/bin/env python
# -*- coding:utf-8 -*-
 
#append追加
name_list = ["zhangyanlin","suoning","nick"]
name_list.append('zhang')
print(name_list)
 
#count制定字符出现几次
name_list = ["zhangyanlin","suoning","nick"]
name_list.append('zhang')
name_list.append('zhang')
name_list.append('zhang')
print(name_list.count('zhang'))
 
#extend可扩展,批量往里加数据
name_list = ["zhangyanlin","suoning","nick"]
name = ["aylin","zhang","yan","lin"]
name_list.extend(name)
print(name_list)
 
#index找到字符所在的位置
name_list = ["zhangyanlin","suoning","nick"]
print(name_list.index('nick'))
 
#insert插入,往索引里面插入值
name_list = ["zhangyanlin","suoning","nick"]
name_list.insert(1,"zhang")
print(name_list)
 
#pop在原列表中移除掉最后一个元素,并赋值给另一个变量
name_list = ["zhangyanlin","suoning","nick"]
name = name_list.pop()
print(name)
 
#remove移除,只移除从左边找到的第一个
name_list = ["zhangyanlin","suoning","nick"]
name_list.remove('nick')
print(name_list)
 
#reverse反转
name_list = ["zhangyanlin","suoning","nick"]
name_list.reverse()
print(name_list)
 
#del删除其中元素,删除1到3之间的
name_list = ["zhangyanlin","suoning","nick"]
del name_list[1:3]
print(name_list)

四.索引

name_list = ["zhangyanlin","suoning""aylin""nick"]
print(name_list[0])

五.切片

name_list = ["zhangyanlin","suoning""aylin""nick"]
print(name_list[0:2])

六.总长度len

name_list = ["zhangyanlin","suoning""aylin""nick"]
print(name_list[1:len(name_list)])

七.for循环

name_list = ["zhangyanlin","suoning""aylin""nick"]
for i in name_list:
  print(i)
Python 相关文章推荐
pyqt4教程之messagebox使用示例分享
Mar 07 Python
Python实现动态添加类的属性或成员函数的解决方法
Jul 16 Python
python使用wmi模块获取windows下的系统信息 监控系统
Oct 27 Python
Python中的浮点数原理与运算分析
Oct 12 Python
python使用pyqt写带界面工具的示例代码
Oct 23 Python
python3实现随机数
Jun 25 Python
Python实现的简单线性回归算法实例分析
Dec 26 Python
Python3.4解释器用法简单示例
Mar 22 Python
Python线程指南分享
Nov 19 Python
python给指定csv表格中的联系人群发邮件(带附件的邮件)
Dec 31 Python
使用Django实现把两个模型类的数据聚合在一起
Mar 28 Python
通过代码实例了解Python sys模块
Sep 14 Python
Python数据类型详解(一)字符串
May 08 #Python
Python常用知识点汇总
May 08 #Python
Python对list列表结构中的值进行去重的方法总结
May 07 #Python
Python环境下安装使用异步任务队列包Celery的基础教程
May 07 #Python
Python编写电话薄实现增删改查功能
May 07 #Python
Python的dict字典结构操作方法学习笔记
May 07 #Python
Python 类与元类的深度挖掘 II【经验】
May 06 #Python
You might like
解决控件遮挡问题:关于有窗口元素和无窗口元素
2007/01/28 PHP
php is_file()和is_dir()用于遍历目录时用法注意事项
2010/03/02 PHP
IIS6.0中配置php服务全过程解析
2013/08/07 PHP
phpexcel导入excel数据使用方法实例
2013/12/24 PHP
PHP随机生成唯一HASH值自定义函数
2015/04/20 PHP
CodeIgniter多语言实现方法详解
2016/01/20 PHP
php基于数组函数实现关联表的编辑操作示例
2017/07/04 PHP
基于jquery的拖动布局插件
2011/11/25 Javascript
js对象关系图 方便dom操作
2012/03/18 Javascript
javascript如何动态加载表格与动态添加表格行
2013/11/27 Javascript
javascript格式化json显示实例分析
2015/04/21 Javascript
Jquery时间轴特效(三种不同类型)
2015/11/02 Javascript
JavaScript前端开发之实现二进制读写操作
2015/11/04 Javascript
Bootstrap轮播加上css3动画,炫酷到底!
2015/12/22 Javascript
jQuery设置Cookie及删除Cookie实例分析
2016/04/15 Javascript
JavaScript Math 对象常用方法总结
2016/04/28 Javascript
jQuery获取多种input值的简单实现方法
2016/06/20 Javascript
angularjs ui-router中路由的二级嵌套
2017/03/10 Javascript
解决vue无法设置滚动位置的问题
2018/10/07 Javascript
[04:04]显微镜下的DOTA2第六期——电影级别的华丽团战
2014/06/20 DOTA
python迭代器实例简析
2014/09/25 Python
在Python中封装GObject模块进行图形化程序编程的教程
2015/04/14 Python
简单介绍python封装的基本知识
2019/08/10 Python
python爬虫 urllib模块url编码处理详解
2019/08/20 Python
python中matplotlib条件背景颜色的实现
2019/09/02 Python
Django生成PDF文档显示网页上以及PDF中文显示乱码的解决方法
2019/12/17 Python
ubuntu16.04升级Python3.5到Python3.7的方法步骤
2020/08/20 Python
python xlsxwriter模块的使用
2020/12/24 Python
浅谈Python xlwings 读取Excel文件的正确姿势
2021/02/26 Python
css3实现小箭头各种图形效果
2020/07/08 HTML / CSS
成品库仓管员岗位职责
2014/04/06 职场文书
高一学生评语大全
2014/04/25 职场文书
学术研讨会欢迎词
2015/01/26 职场文书
2016寒假社会实践心得体会范文
2015/10/09 职场文书
用Python提取PDF表格的方法
2021/04/11 Python
python实现简单石头剪刀布游戏
2021/10/24 Python