Simplify the declarations of the Python code.

This commit is contained in:
krahets
2023-05-22 22:03:57 +08:00
parent 081b76d620
commit e196962d0a
27 changed files with 88 additions and 87 deletions

View File

@ -70,9 +70,9 @@ def find(nums: list[int], target: int) -> int:
"""Driver Code"""
if __name__ == "__main__":
# 初始化数组
arr: list[int] = [0] * 5
arr = [0] * 5
print("数组 arr =", arr)
nums: list[int] = [1, 3, 2, 5, 4]
nums = [1, 3, 2, 5, 4]
print("数组 nums =", nums)
# 随机访问

View File

@ -7,7 +7,7 @@ Author: Krahets (krahets@163.com)
"""Driver Code"""
if __name__ == "__main__":
# 初始化列表
arr: list[int] = [1, 3, 2, 5, 4]
arr = [1, 3, 2, 5, 4]
print("列表 arr =", arr)
# 访问元素
@ -39,17 +39,17 @@ if __name__ == "__main__":
print("删除索引 3 处的元素,得到 arr =", arr)
# 通过索引遍历列表
count: int = 0
count = 0
for i in range(len(arr)):
count += 1
# 直接遍历列表元素
count: int = 0
count = 0
for n in arr:
count += 1
# 拼接两个列表
arr1: list[int] = [6, 8, 7, 10, 9]
arr1 = [6, 8, 7, 10, 9]
arr += arr1
print("将列表 arr1 拼接到 arr 之后,得到 arr =", arr)