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 相关文章推荐
Python实现全局变量的两个解决方法
Jul 03 Python
使用Python的Treq on Twisted来进行HTTP压力测试
Apr 16 Python
通过Python实现自动填写调查问卷
Sep 06 Python
Python编程使用NLTK进行自然语言处理详解
Nov 16 Python
python编写朴素贝叶斯用于文本分类
Dec 21 Python
Python使用jsonpath-rw模块处理Json对象操作示例
Jul 31 Python
python requests.post带head和body的实例
Jan 02 Python
python在openstreetmap地图上绘制路线图的实现
Jul 11 Python
Python高级编程之消息队列(Queue)与进程池(Pool)实例详解
Nov 01 Python
将python文件打包exe独立运行程序方法详解
Feb 12 Python
详解Python中的进程和线程
Jun 23 Python
Python利用Turtle绘制哆啦A梦和小猪佩奇
Apr 04 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
PHP安装攻略:常见问题解答(一)
2006/10/09 PHP
php 采集书并合成txt格式的实现代码
2009/03/01 PHP
php网页标题中文乱码的有效解决方法
2014/03/05 PHP
PHP+Apache+Mysql环境搭建教程
2016/08/01 PHP
详解php与ethereum客户端交互
2018/04/28 PHP
laravel 实现设置时区的简单方法
2019/10/10 PHP
Laravel基础-关于引入公共文件的两种方式
2019/10/18 PHP
js冒泡、捕获事件及阻止冒泡方法详细总结
2014/05/08 Javascript
jQuery实现Twitter的自动文字补齐特效
2014/11/28 Javascript
JS实现鼠标箭头变成一个燃烧烛光效果的方法
2015/02/28 Javascript
Underscore.js 1.3.3 中文注释翻译说明
2015/06/25 Javascript
JS实现输入框提示文字点击时消失效果
2016/07/19 Javascript
js实现无缝滚动图(可控制当前滚动的方向)
2017/02/22 Javascript
js 获取元素的具体样式信息getcss(实例讲解)
2017/07/05 Javascript
layui框架中layer父子页面交互的方法分析
2017/11/15 Javascript
微信小程序仿微信运动步数排行(交互)
2018/07/13 Javascript
bootstrap select2插件用ajax来获取和显示数据的实例
2018/08/09 Javascript
在webstorm开发微信小程序之使用阿里自定义字体图标的方法
2018/11/15 Javascript
微信小程序遍历Echarts图表实现多个饼图
2019/04/25 Javascript
微信小程序系列之自定义顶部导航功能
2019/05/21 Javascript
jquery获取input输入框中的值
2019/11/13 jQuery
python开发中range()函数用法实例分析
2015/11/12 Python
python 环境变量和import模块导入方法(详解)
2017/07/11 Python
wxPython实现窗口用图片做背景
2018/04/25 Python
浅谈Python traceback的优雅处理
2018/08/31 Python
学生信息管理系统python版
2018/10/17 Python
python 采用paramiko 远程执行命令及报错解决
2019/10/21 Python
船餐厅和泰晤士河餐饮游轮:Bateaux London
2018/03/19 全球购物
英国演唱会订票网站:Ticket Selection
2018/03/27 全球购物
经典促销广告词大全
2014/03/19 职场文书
小学教师寄语大全
2014/04/03 职场文书
四年级学生评语大全
2014/04/21 职场文书
王力宏牛津大学演讲稿
2014/05/22 职场文书
大学毕业生管理学求职信
2014/09/01 职场文书
2015年感恩母亲节活动方案
2015/05/04 职场文书
民间借贷借条范本
2015/05/25 职场文书