zoukankan      html  css  js  c++  java
  • 一、初识Python ----- 人人都爱列表

    python列表的创建与访问

    movies = ["The Holy Grail","The Life of Brian","The Meaning of Life"]
    print(movies[1])

    列表常用的BIF

    print() 显示列表内容 

    len() 计算列表的数据项

    append() 在列表末尾增加一个数据项         extend() 在列表末尾增加一个数据项集合

    pop() 从列表末尾删除数据

    remove() 找到并删除一个特定的数据项

    insert() 在特定位置前增加一个数据项

    cast = ["Cleese","Palin","Jones","Idle"]
    print(cast)
    print(len(cast))
    
    cast.append("Gilliam")   #末尾增加
    cast.pop()  #删除末尾数据
    cast.extend(["Gilliam","Chapman"]) #增加一个数据集合
    cast.remove("Cleese") #删除特定项
    cast.insert(0,"Chapman")  #在位置0之前增加一项

    python中的for循环

    movies = ["The Holy Grail","The Life of Brian"]
    
    for each in movies :
        print(each)

    查询python内置方法与功能描述

    dir(__builtins__)  #内置方法列表
    help(input)  #得到input()这个函数的功能描述

    isinstance()如何工作

    names = ['Michael','Terry']
    isinstance(names,list) #判断names是否属于list类型 如果是返回true
    
    num_names = len(names)
    isinstance(num_names,list) #此句返回false

    利用递归,建立函数迭代输出含嵌套的列表

    movies = ["The Holy Grail",1975,"Terry jones & Terry Gilliam",97,
                           ["Graham Chapman",["Michael Palin","John Cleese",
                                  "Terry Gilliam","Eric Idle","Terry Jones"]]]
    
    def print_lol(the_list):
        for each_item in the_list:
            if isinstance(each_item,list):
                print_lol(each_item)        #递归调用
            else:
                print(each_item)
    
    print_lol(movies)
  • 相关阅读:
    (五)Hibernate 操作对象
    (四)关联关系一对多映射
    (三)映射对象标识符(OID)
    随机取数据
    Delphi的时间处理
    调用MYSQL存储过程实例
    php接收数据
    NodeJS入门
    idHTTP访问百度
    delphi 从TWebBrowser WebBrowser得到全部html源码
  • 原文地址:https://www.cnblogs.com/bing0818/p/4882778.html
Copyright © 2011-2022 走看看