python3: dlt - 数据结构
一、程序:
1 [wit@fedora null]$ cat test.py 2 #!/usr/bin/env python3 3 4 5 6 7 # test this script 8 def msg(): 9 print("\nhello, python3!\n") 10 11 12 # running msg() 13 # msg() 14 15 16 17 18 # define class for data 19 class dlt_data: 20 def __init__(self): 21 self.no = 0 22 self.id = [] 23 self.f = [] 24 self.b = [] 25 26 def set(self, uno, uid, ufront, uback): 27 self.no = uno 28 self.id = uid 29 self.f.extend(ufront) 30 self.b.extend(uback) 31 32 def title(self): 33 print(f"\n\tNo.\tid\t\tfront\t\t\t\t\t-\tback\t\n") 34 35 def empty_line(sef): 36 print(f"\n") 37 38 def say(self): 39 print(f"\t{self.no}\t{self.id}\t\t{self.f[0]}\t{self.f[1]}\t{self.f[2]}\t{self.f[3]}\t{self.f[4]}\t-\t{self.b[0]}\t{self.b[1]}") 40 41 42 43 44 45 """ 46 dlt = dlt_data() 47 dlt.set(1, 2023001, [18, 19, 24, 27, 34], [11, 12]) 48 dlt.title() 49 dlt.say() 50 """ 51 52 53 54 55 # display result for testing 56 57 58 """ 59 dlt = [] 60 61 62 for i in [0,1,2,3,4]: 63 dlt.append(dlt_data()) 64 i = 0 65 66 67 c = 0 68 for d in dlt: 69 d.set(c, 2023001+c, [1,12,23,34,35], [1,4]) 70 c = c + 1 71 c = 0 72 73 74 dlt[0].title() 75 for x in dlt: 76 x.say() 77 dlt[0].empty_line() 78 """ 79 80 81 82 # define funtion 83 def speak(): 84 85 dlt = [] 86 87 88 for i in [0,1,2,3,4]: 89 dlt.append(dlt_data()) 90 i = 0 91 92 93 c = 0 94 for d in dlt: 95 d.set(c, 2023001+c, [1,12,23,34,35], [1,4]) 96 c = c + 1 97 c = 0 98 99 100 dlt[0].title() 101 for x in dlt: 102 x.say() 103 dlt[0].empty_line() 104 105 106 107 # define funtion 108 def speak2(): 109 110 dlt = [] 111 112 scope = 30 113 for i in range(scope): 114 x = dlt_data() 115 x.set(i, 2022001+i, [2, 4, 7, 14, 31], [3, 9]) 116 dlt.append(x) 117 i = 0 118 119 120 dlt[0].title() 121 for x in dlt: 122 x.say() 123 x = [] 124 dlt[0].empty_line() 125 126 127 # test part 128 if __name__ == "__main__": 129 #speak() 130 speak2() 131 [wit@fedora null]$ 132 [wit@fedora null]$
二、运行结果:
1 [wit@fedora null]$ ./test.py 2 3 No. id front - back 4 5 0 2022001 2 4 7 14 31 - 3 9 6 1 2022002 2 4 7 14 31 - 3 9 7 2 2022003 2 4 7 14 31 - 3 9 8 3 2022004 2 4 7 14 31 - 3 9 9 4 2022005 2 4 7 14 31 - 3 9 10 5 2022006 2 4 7 14 31 - 3 9 11 6 2022007 2 4 7 14 31 - 3 9 12 7 2022008 2 4 7 14 31 - 3 9 13 8 2022009 2 4 7 14 31 - 3 9 14 9 2022010 2 4 7 14 31 - 3 9 15 10 2022011 2 4 7 14 31 - 3 9 16 11 2022012 2 4 7 14 31 - 3 9 17 12 2022013 2 4 7 14 31 - 3 9 18 13 2022014 2 4 7 14 31 - 3 9 19 14 2022015 2 4 7 14 31 - 3 9 20 15 2022016 2 4 7 14 31 - 3 9 21 16 2022017 2 4 7 14 31 - 3 9 22 17 2022018 2 4 7 14 31 - 3 9 23 18 2022019 2 4 7 14 31 - 3 9 24 19 2022020 2 4 7 14 31 - 3 9 25 20 2022021 2 4 7 14 31 - 3 9 26 21 2022022 2 4 7 14 31 - 3 9 27 22 2022023 2 4 7 14 31 - 3 9 28 23 2022024 2 4 7 14 31 - 3 9 29 24 2022025 2 4 7 14 31 - 3 9 30 25 2022026 2 4 7 14 31 - 3 9 31 26 2022027 2 4 7 14 31 - 3 9 32 27 2022028 2 4 7 14 31 - 3 9 33 28 2022029 2 4 7 14 31 - 3 9 34 29 2022030 2 4 7 14 31 - 3 9 35 36 37 [wit@fedora null]$
三、参考文档
1、Python3 列表| 菜鸟教程 https://www.runoob.com/python3/python3-list.html
2、Python3 面向对象|菜鸟教程 https://www.runoob.com/python3/python3-class.html
标签:14,self,def,dlt,数据结构,31,python3 From: https://www.cnblogs.com/lnlidawei/p/17825107.html