python列表的简单使用

    xiaoxiao2021-03-26  21

    python列表是一个很好用的工具,他就像C语言中的数组,但是又可以混杂不同类型的数据。

    1.列表的创建

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

    列表可以按数组的形式来读取想要的字符串或者其他类型的数据

    2.列表的插入与删除 movies.append("The First Blood") movies.pop() movies.extend(["Love in The World","Second Yesterday"]) print(movies) movies.remove("Second Yesterday") print(movies) movies.insert(1,1973) movies.insert(3,1979) movies.append(1983) print(movies) append()函数可以在列表的末尾插入一个数据

    pop()函数可以删除末尾的一个数据

    extend()函数可以在末尾插入任意个数据

    remove()函数可以移除一个指定的数据

    insert()函数可以在指定的位置插入一个数据

    3.列表的清除

    movies.clear()

    4.列表的打印

    for each in movies: print(each) count=0 while count<len(movies): print(movies[count]) count+=1

    转载请注明原文地址: https://ju.6miu.com/read-600310.html

    最新回复(0)