列表是一种非常简单的数组。他们可以包含任意的类型的变量,包含任意多个变量。同时列表的遍历是非常简单的。 1234567891011 mylist = []mylist.append(1)mylist.append(2)mylist.append(3)print(mylist[0]) # prints 1print(mylist[1]) # prints 2print(mylist[2]) # prints 3# prints out 1,2,3for x in mylist: print(x) 如果你视图访问一个不存在的列表,将会报错而不是异常 12 mylist = [1,2,3]print(mylist[10]) 联系 1234567891011121314151617181920 numbers = []strings = []names = ["John", "Eric", "Jessica"]# write your code heresecond_name = names[1]for i in range(1,4): numbers.append(i)for s in ["hello","world"]: strings.append(s)# this code should write out the filled arrays and the second name in the names list (Eric).print(numbers)print(strings)print("The second name on the names list is %s" % second_name) 赞微海报分享
近期评论