列表数据类型

列表包含以逗号分隔并包含在方括号[]中的项目。列表几乎与 C 中的数组类似。一个区别是属于列表的所有项目可以是不同的数据类型。

list = [123,'abcd',10.2,'d']    #can be a array of any data type or single data type.
list1 = ['hello','world']
print(list)    #will ouput whole list. [123,'abcd',10.2,'d']
print(list[0:2])    #will output first two element of list. [123,'abcd']
print(list1 * 2)    #will gave list1 two times. ['hello','world','hello','world']
print(list + list1)    #will gave concatenation of both the lists. [123,'abcd',10.2,'d','hello','world']