深入了解Python数据类型之列表


Posted in Python onJune 24, 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数据类型之列表全部内容了,希望大家多多支持三水点靠木~

Python 相关文章推荐
简介二分查找算法与相关的Python实现示例
Aug 26 Python
使用Python导出Excel图表以及导出为图片的方法
Nov 07 Python
Python中 Lambda表达式全面解析
Nov 28 Python
Python字符串格式化的方法(两种)
Sep 19 Python
Python使用try except处理程序异常的三种常用方法分析
Sep 05 Python
python实现K近邻回归,采用等权重和不等权重的方法
Jan 23 Python
python利用多种方式来统计词频(单词个数)
May 27 Python
Python3 串口接收与发送16进制数据包的实例
Jun 12 Python
Django CBV模型源码运行流程详解
Aug 17 Python
基于python实现简单C/S模式代码实例
Sep 14 Python
Python基于execjs运行js过程解析
Nov 27 Python
python中yield的用法详解
Jan 13 Python
Python实现信用卡系统(支持购物、转账、存取钱)
Jun 24 #Python
Python提取Linux内核源代码的目录结构实现方法
Jun 24 #Python
Linux上安装Python的PIL和Pillow库处理图片的实例教程
Jun 23 #Python
尝试用最短的Python代码来实现服务器和代理服务器
Jun 23 #Python
Python基础篇之初识Python必看攻略
Jun 23 #Python
浅谈python中scipy.misc.logsumexp函数的运用场景
Jun 23 #Python
浅谈Python中用datetime包进行对时间的一些操作
Jun 23 #Python
You might like
PHP 面向对象实现代码
2009/11/11 PHP
php筛选不存在的图片资源
2015/04/28 PHP
PHP加密解密函数详解
2015/10/28 PHP
给Function做的OOP扩展
2009/05/07 Javascript
修改jQuery Validation里默认的验证方法
2012/02/14 Javascript
JavaScript高级程序设计(第3版)学习笔记3 js简单数据类型
2012/10/11 Javascript
javascript获取下拉列表框当中的文本值示例代码
2013/07/31 Javascript
超级简单的jquery操作表格方法
2014/12/15 Javascript
jQuery实现数字加减效果汇总
2014/12/16 Javascript
js实现iGoogleDivDrag模块拖动层拖动特效的方法
2015/03/04 Javascript
js实现仿阿里巴巴城市选择框效果实例
2015/06/24 Javascript
使用伪命名空间封装保护独自创建的对象方法
2016/08/04 Javascript
基于Node.js + WebSocket打造即时聊天程序嗨聊
2016/11/29 Javascript
详解Vue生命周期的示例
2017/03/10 Javascript
详解easyui基于 layui.laydate日期扩展组件
2018/07/18 Javascript
Element PageHeader页头的使用方法
2020/07/26 Javascript
[03:07]DOTA2英雄基础教程 冰霜诅咒极寒幽魂
2013/12/06 DOTA
Python3实现连接SQLite数据库的方法
2014/08/23 Python
非递归的输出1-N的全排列实例(推荐)
2017/04/11 Python
Python实现监控键盘鼠标操作示例【基于pyHook与pythoncom模块】
2018/09/04 Python
python 对给定可迭代集合统计出现频率,并排序的方法
2018/10/18 Python
python之拟合的实现
2019/07/19 Python
Python 70行代码实现简单算式计算器解析
2019/08/30 Python
Python字典实现伪切片功能
2020/10/28 Python
澳大利亚当地最大的时装生产商:Cue
2018/08/06 全球购物
什么是数据抽象
2016/11/26 面试题
教师实习自我鉴定
2013/12/18 职场文书
四年大学自我鉴定
2014/02/17 职场文书
《棉鞋里的阳光》教学反思
2014/04/24 职场文书
2014年党的群众路线整改措施思想汇报
2014/10/12 职场文书
幼儿园2015年度工作总结
2015/04/01 职场文书
雨雪天气温馨提示
2015/07/15 职场文书
小学体育跳绳课教学反思
2016/02/16 职场文书
闭幕词的写作格式与范文!
2019/06/24 职场文书
导游词之安徽九华山
2019/09/18 职场文书
JAVA 线程池(池化技术)的实现原理
2022/04/28 Java/Android