国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Python數(shù)據(jù)類(lèi)型詳解(二)列表

2020-01-04 17:28:58
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
本文給大家詳細(xì)介紹的是Python數(shù)據(jù)類(lèi)型中的列表(list),非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下
 

一.基本數(shù)據(jù)類(lèi)型

  整數(shù):int
  字符串:str(注:/t等于一個(gè)tab鍵)
  布爾值: bool
  列表:list (元素的集合)
  列表用[]
  元祖:tuple
  元祖用()
  字典:dict

注:所有的數(shù)據(jù)類(lèi)型都存在想對(duì)應(yīng)的類(lèi)列里

二.列表所有數(shù)據(jù)類(lèi)型:

基本操作:

索引,切片,追加,刪除,長(zhǎng)度,切片,循環(huán),包含

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(對(duì)象)- >——沒(méi)有一個(gè)對(duì)象附加到結(jié)束)    pass  def clear(self): # real signature unknown; restored from __doc__    """ L.clear() -> None -- remove all items from L """    (L.clear()- >沒(méi)有,把所有項(xiàng)目從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(價(jià)值)- >整數(shù),返回值的出現(xiàn)次數(shù))    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)- >沒(méi)有——從iterable擴(kuò)展列表通過(guò)添加元)    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指數(shù)(價(jià)值,[開(kāi)始,[不要]])- >整數(shù),返回第一索引值。提出了ValueError如果不存在的價(jià)值。)    """    return 0  def insert(self, index, p_object): # real signature unknown; restored from __doc__    """ L.insert(index, object) -- insert object before index """    (l插入(指數(shù)(對(duì)象)——前插入對(duì)象索引)    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((指數(shù)))- >項(xiàng)目——刪除并返回項(xiàng)指數(shù)(默認(rèn))。提出了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(價(jià)值)- >沒(méi)有,刪除第一次出現(xiàn)的值。提出了ValueError如果不存在的價(jià)值。)    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

三.所有列表數(shù)據(jù)類(lèi)型舉例

#!/usr/bin/env python# -*- coding:utf-8 -*- #append追加name_list = ["zhangyanlin","suoning","nick"]name_list.append('zhang')print(name_list) #count制定字符出現(xiàn)幾次name_list = ["zhangyanlin","suoning","nick"]name_list.append('zhang')name_list.append('zhang')name_list.append('zhang')print(name_list.count('zhang')) #extend可擴(kuò)展,批量往里加數(shù)據(jù)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在原列表中移除掉最后一個(gè)元素,并賦值給另一個(gè)變量name_list = ["zhangyanlin","suoning","nick"]name = name_list.pop()print(name) #remove移除,只移除從左邊找到的第一個(gè)name_list = ["zhangyanlin","suoning","nick"]name_list.remove('nick')print(name_list) #reverse反轉(zhuǎn)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])

六.總長(zhǎng)度len

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

七.for循環(huán)

name_list = ["zhangyanlin","suoning""aylin""nick"]for i in name_list:  print(i)

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南充市| 红安县| 克山县| 白银市| 富阳市| 灵石县| 高青县| 交城县| 临武县| 灵山县| 济源市| 确山县| 长岭县| 鄢陵县| 永嘉县| 双城市| 梨树县| 望江县| 庆安县| 永济市| 太保市| 南投县| 墨江| 吉首市| 东港市| 台湾省| 镇雄县| 美姑县| 高安市| 新巴尔虎左旗| 苍山县| 阿拉善左旗| 赤壁市| 兴宁市| 夏津县| 潍坊市| 平泉县| 玛多县| 阳江市| 桂平市| 库伦旗|