【Python】数组的使用

tech2025-01-27  28

Python中数组又叫列表:

list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5 ] list3 = ["a", "b", "c", "d"] print "list1[0]: ", list1[0] print "list2[1:5]: ", list2[1:5] list = [] ## 空列表 list.append('Google') ## 使用 append() 添加元素 list.append('Runoob') print list ################################3 list1 = ['physics', 'chemistry', 1997, 2000] list1.append('Google') ## 使用 append() 添加元素 list1.append('Runoob') list1.remove(1997) list1.__delitem__(1) print (list1)

 

 

//题目:输入三个整数x,y,z,请把这三个数由小到大输出。 l = [] for i in range(3): x = int(raw_input('integer:\n')) l.append(x) l.sort() print l

 

最新回复(0)