List
effect
Storing a plurality of values, such as a plurality of girlfriend, a plurality of hobbies.
definition
Any type of value are separated by a comma within [].
hobby = 'read'
hobby_list = [hobby, 'run', 'girl']
print(id(hobby_list))
print(type(hobby_list))
print(hobby_list)
# 输出结果
# 4558605960
# <class 'list'>
# ['read', 'run', 'girl']
use
Deposit is not an end, is taking aim, we introduce the method list index value, bearing in mind the index number from zero.
hobby_list = ['read', 'run', 'girl']
# 索引序号 0 1 2
# 取出第二个爱好
print(hobby_list[1])
# 输出结果
# run
hobby_list = ['read', 'run', ['girl_name', 18, 'shanghai']]
# 取出girl的年龄
print(hobby_list[2][1])
# 输出结果
# 18