机器学习 第一章 Python复习(2)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huxiaotong_exp/article/details/82557653

第二课 数据结构之list

list

参考文档
定义一个数组,可以放数字、字符串、甚至一个函数,可以直接运行数组中的函数

def showMe():
    print("xiaotong")
items = [23,'男',showMe]
items[2]()

如下案例来自官网,供后续参考

>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4)  # Find next banana starting a position 4
6
>>> fruits.reverse()
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
>>> fruits.append('grape')
>>> fruits
['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']
>>> fruits.sort()
>>> fruits
['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
>>> fruits.pop()
'pear'

猜你喜欢

转载自blog.csdn.net/huxiaotong_exp/article/details/82557653