温馨提示:本文最后更新于
2024-12-11 14:51:35
,某些文章具有时效性,若有错误或已失效,请在下方留言。Python 内置函数的详情可参考 https://docs.python.org/zh-cn/3.13/library/functions.html
函数定义
无参函数的语法
# 函数定义
def <function name>():
# Do something
# 函数调用
<function name>()
示例代码
# 函数定义
def get_user_name():
name = input("What is your name? ")
print("Hello, " + name)
# 函数调用
get_user_name()
缩进
Python 中的缩进是由四个空格
组成。
while 循环
while
循环的基语法如下所示
while something_is_true:
# Do something repeatly
示例代码
num = 6
while num > 0:
jump()
# 改变循环条件变量
num -= 1
print(num)
© 版权声明
THE END
暂无评论内容