Add typing annotations to Python codes. (#411)

This commit is contained in:
Yudong Jin
2023-03-12 18:49:52 +08:00
committed by GitHub
parent 2029d2b939
commit 9151eaf533
50 changed files with 577 additions and 817 deletions

View File

@ -13,7 +13,7 @@ from modules import *
if __name__ == "__main__":
""" 初始化栈 """
# Python 没有内置的栈类,可以把 list 当作栈来使用
stack = []
stack: List[int] = []
""" 元素入栈 """
stack.append(1)
@ -24,18 +24,18 @@ if __name__ == "__main__":
print("栈 stack =", stack)
""" 访问栈顶元素 """
peek = stack[-1]
peek: int = stack[-1]
print("栈顶元素 peek =", peek)
""" 元素出栈 """
pop = stack.pop()
pop: int = stack.pop()
print("出栈元素 pop =", pop)
print("出栈后 stack =", stack)
""" 获取栈的长度 """
size = len(stack)
size: int = len(stack)
print("栈的长度 size =", size)
""" 判断是否为空 """
is_empty = len(stack) == 0
is_empty: bool = len(stack) == 0
print("栈是否为空 =", is_empty)