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

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

Pyhon 基础语法复习

第二课 数据结构 list类型 map乐类型 定义类

数据类型之list

参考文档

def showMe(name):
    print("my name is " + name)
# 列表,可以放字符串、数字、甚至一个函数
items = ["male",19,showMe]
for item in items:
    print(item)
# 可以直接这样执行函数
items[2]()

list其他内置函数举例(来自官网)

>>> 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/82355289