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

 更新时间:2016年06月24日 10:44:30   投稿:jingxian  
下面小编就为大家带来一篇深入了解Python数据类型之列表。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

一.基本数据类型

整数: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数据类型之列表全部内容了,希望大家多多支持脚本之家~

相关文章

  • 使用Matplotlib绘制不同颜色的带箭头的线实例

    使用Matplotlib绘制不同颜色的带箭头的线实例

    这篇文章主要介绍了使用Matplotlib绘制不同颜色的带箭头的线实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-04-04
  • Numpy广播域的理解

    Numpy广播域的理解

    本文主要介绍了Numpy广播域的理解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-03-03
  • Django操作session 的方法

    Django操作session 的方法

    这篇文章主要介绍了Django操作session 的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-03-03
  • python保存文件方法小结

    python保存文件方法小结

    这篇文章主要介绍了python保存文件方法小结,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-07-07
  • 为python爬虫docker镜像添加nodejs环境实现方法

    为python爬虫docker镜像添加nodejs环境实现方法

    这篇文章主要为大家介绍了为python爬虫docker镜像添加nodejs环境实现方法,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-09-09
  • Python正则表达式知识汇总

    Python正则表达式知识汇总

    本文介绍了Python正则表达式的相关基础知识,本文的内容不包括如何编写高效的正则表达式、如何优化正则表达式,这些主题请查看其他教程。
    2017-09-09
  • python保留小数点位数的多种方式(附demo)

    python保留小数点位数的多种方式(附demo)

    在Python中,保留小数点后特定位数可以通过多种方式实现,以下是几种常见的方法,并附上相应的代码示例,使用字符串格式化,使用round()函数,使用Decimal模块和使用numpy库,文中通过代码讲解的非常详细,需要的朋友可以参考下
    2024-06-06
  • python daemon守护进程实现

    python daemon守护进程实现

    这篇文章主要介绍了python daemon守护进程实现,需要的朋友可以参考下
    2016-08-08
  • 如何提取Playwright录制文件中的元素定位信息

    如何提取Playwright录制文件中的元素定位信息

    最近在学习Playwright自动化测试,本文主要介绍了如何提取Playwright录制文件中的元素定位信息,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-12-12
  • Python3开发实例之非关系型图数据库Neo4j安装方法及Python3连接操作Neo4j方法实例

    Python3开发实例之非关系型图数据库Neo4j安装方法及Python3连接操作Neo4j方法实例

    这篇文章主要介绍了Python3开发实例之非关系型图数据库Neo4j安装方法及Python3连接操作Neo4j方法实例,需要的朋友可以参考下
    2020-03-03

最新评论