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 """
  • 相关阅读:
    ffmpeg rtmp推流 视频转码
    java日志发展史 log4j slf4j log4j2 jul jcl 日志和各种桥接包的关系
    nginx stream 流转发,可以转发rtmp、mysql访问流,转发rtmp、jdbc请求
    java web http 转https 通过nginx代理访问
    linux 服务器磁盘挂载
    novnc 通过websockify代理 配置多点访问
    linux 文件服务 minio 安装部署配置
    AOP实现原理,手写aop
    java 泛型
    JAVA反射getGenericSuperclass()用法
  • 原文地址:https://www.cnblogs.com/milantgh/p/3603291.html
Copyright © 2011-2022 走看看