mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-28 16:44:22 +00:00
Add typing annotations to Python codes. (#411)
This commit is contained in:
@@ -12,11 +12,11 @@ from modules import *
|
||||
""" Driver Code """
|
||||
if __name__ == "__main__":
|
||||
""" 初始化列表 """
|
||||
list = [1, 3, 2, 5, 4]
|
||||
list: List[int] = [1, 3, 2, 5, 4]
|
||||
print("列表 list =", list)
|
||||
|
||||
""" 访问元素 """
|
||||
num = list[1]
|
||||
num: int = list[1]
|
||||
print("访问索引 1 处的元素,得到 num =", num)
|
||||
|
||||
""" 更新元素 """
|
||||
@@ -44,17 +44,17 @@ if __name__ == "__main__":
|
||||
print("删除索引 3 处的元素,得到 list =", list)
|
||||
|
||||
""" 通过索引遍历列表 """
|
||||
count = 0
|
||||
count: int = 0
|
||||
for i in range(len(list)):
|
||||
count += 1
|
||||
|
||||
""" 直接遍历列表元素 """
|
||||
count = 0
|
||||
count: int = 0
|
||||
for n in list:
|
||||
count += 1
|
||||
|
||||
""" 拼接两个列表 """
|
||||
list1 = [6, 8, 7, 10, 9]
|
||||
list1: List[int] = [6, 8, 7, 10, 9]
|
||||
list += list1
|
||||
print("将列表 list1 拼接到 list 之后,得到 list =", list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user