zoukankan      html  css  js  c++  java
  • python之BIF函数在列表中的应用

     1 Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] on win32
    
    2 Type "copyright", "credits" or "license()" for more information.
    3 >>> cast=["cleese","palin","jones","idle"]
    4 >>> print(cast)
    5 [""cleese"", ""palin"", ""jones"", ""idle""]
    6 >>> print(len(cast))#显示数据项数量
    7 4
    8 >>> print(cast[1])#显示列表中第2个数据项的值
    9 palin
    10 >>> cast.append("gilliam")#在列表末尾添加一个数据项
    11 >>> print(cast)
    12 [""cleese"", ""palin"", ""jones"", ""idle"", ""gilliam""]
    13 >>> cast.pop()#删除列表末尾的数据项
    14 ""gilliam""
    15 >>> print(cast)
    16 [""cleese"", ""palin"", ""jones"", ""idle""]
    17 >>> cast.extend(["gilliam","chapman"])#在列表末尾增长一个数据项凑集
    18 >>> print(cast)
    19 [""cleese"", ""palin"", ""jones"", ""idle"", ""gilliam"", ""chapman""]
    20 >>> cast.remove("chapman")#删除指定的数据项
    21 >>> print(cast)
    22 [""cleese"", ""palin"", ""jones"", ""idle"", ""gilliam""]
    23 >>> cast.(0,"chapman")#在指定的地位增长数据项
    24 >>> print(cast)
    25 [""chapman"", ""cleese"", ""palin"", ""jones"", ""idle"", ""gilliam""]
    26 >>>



    下面是讲定义一个def函数,isinstance()函数,for in,if else等的应用以及逻辑


     1 movies=["the holy grail",1975,"terry jone & terry gilliam",91,
    
    2 ["graham chapman",
    3 ["michael palin","john cleese","terry gilliam",
    4 "eric idle","terry jones"]]]
    5 def print_something(the_list):#定义一种函数
    6 for each_item in the_list:#for in轮回迭代处理惩罚列表,从列表肇端地位到末尾
    7 if isinstance(each_item,list):#isinstance()检测each_item里每一项
    8 #是不是list类型
    9 print_something(each_item)#若是是,调用函数print_something
    10 else:print(each_item)#若是不是,输出这一项
    11
    12 print_something(movies)#在movies列表中调用函数
    13 """
    14 之前if else语句不合错误齐导致报错
    15 """
  • 相关阅读:
    [zz]libvirt中CPU和内存的细粒度管理机制
    SAP 模块中文解释
    邪恶的Php一句话木马 assert函数制作简单木马
    PHP开发中三维数组的应用
    返回本机时间或服务器时间
    向SQL中插入数据
    Word的字体
    人生如锅
    打开指定的文件
    计算最大序号
  • 原文地址:https://www.cnblogs.com/milantgh/p/3603291.html
Copyright © 2011-2022 走看看