深入了解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 字符串格式化代码
Mar 17 Python
用smtplib和email封装python发送邮件模块类分享
Feb 17 Python
Python处理文本文件中控制字符的方法
Feb 07 Python
Python实现的快速排序算法详解
Aug 01 Python
windows下安装Python的XlsxWriter模块方法
May 03 Python
对python中的xlsxwriter库简单分析
May 04 Python
手把手教你如何安装Pycharm(详细图文教程)
Nov 28 Python
在unittest中使用 logging 模块记录测试数据的方法
Nov 30 Python
python实现三次样条插值
Dec 17 Python
django数据关系一对多、多对多模型、自关联的建立
Jul 24 Python
Django后端发送小程序微信模板消息示例(服务通知)
Dec 17 Python
如何在Python中妥善使用进度条详解
Apr 05 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读取30天之内的根据算法排序的代码
2008/04/06 PHP
php 注释规范
2012/03/29 PHP
php实现爬取和分析知乎用户数据
2016/01/26 PHP
PHP用户验证和标签推荐的简单使用
2016/10/31 PHP
脚本安需导入(装载)的三种模式的对比
2007/06/24 Javascript
Javscript删除数组中指定元素并返回新数组
2014/03/06 Javascript
JavaScript中的原型链prototype介绍
2014/12/30 Javascript
jQuery实现仿淘宝带有指示条的图片转动切换效果完整实例
2015/03/04 Javascript
使用jquery动态加载Js文件和Css文件
2015/10/24 Javascript
关于JS中setTimeout()无法调用带参函数问题的解决方法
2016/06/21 Javascript
Vue.js组件tree实现无限级树形菜单
2016/12/02 Javascript
详解angularjs实现echart图表效果最简洁教程
2017/11/29 Javascript
微信小程序提交form操作示例
2018/12/30 Javascript
什么时候不能在 Node.js 中使用 Lock Files
2019/06/24 Javascript
vue element 生成无线级左侧菜单的实现代码
2019/08/21 Javascript
关于vue.js中实现方法内某些代码延时执行
2019/11/14 Javascript
使用Vant完成DatetimePicker 日期的选择器操作
2020/11/12 Javascript
Python中计算三角函数之cos()方法的使用简介
2015/05/15 Python
python实现将读入的多维list转为一维list的方法
2018/06/28 Python
对python pandas 画移动平均线的方法详解
2018/11/28 Python
pyQt5实时刷新界面的示例
2019/06/25 Python
python动态进度条的实现代码
2019/07/03 Python
浅谈Python 敏感词过滤的实现
2019/08/15 Python
Python在OpenCV里实现极坐标变换功能
2019/09/02 Python
Original Penguin英国官方网站:美国著名休闲时装品牌
2016/10/30 全球购物
生物制药毕业生自荐信
2013/10/16 职场文书
给实习单位的感谢信
2014/02/01 职场文书
医学类个人求职信范文
2014/02/05 职场文书
《鞋匠的儿子》教学反思
2014/03/02 职场文书
2014年妇产科工作总结
2014/12/08 职场文书
安全主题班会教案
2015/08/12 职场文书
合作合同协议书
2016/03/21 职场文书
Nginx域名转发使用场景代码实例
2021/03/31 Servers
MySQL系列之五 视图、存储函数、存储过程、触发器
2021/07/02 MySQL
MySQL8.0升级的踩坑历险记
2021/11/01 MySQL
js面向对象编程OOP及函数式编程FP区别
2022/07/07 Javascript