2、input输入
#输入格式为:3 4 5
a, b, c = map(int, input().split())
#输入格式为:3,4,5
a, b, c = map(int, input().split(','))
3、for
一般会结合range使用,range(start, stop, step)
参数说明:
- start: 计数从 start 开始。默认是从 0 开始。例如range(5)等价于range(0, 5); stop: 计数到
- stop 结束,但不包括 stop。例如:range(0, 5) 是[0, 1, 2, 3, 4]没有5
- step:步长,默认为1。例如:range(0, 5) 等价于 range(0, 5, 1)
#打印0-4
for i in range(0, 5, 1):
print(i)
4、pass
pass占位,防止语法出错。
if下面一行加入pass,防止编译器报错。
5、help(fun)
调用函数help,形参为函数头,即会打印该函数的说明文档。
def add_num(a, b):
"""两数相加"""
return a + b
help(add_num)
help(sum)
打印信息
Help on function add_num in module __main__:
add_num(a, b)
两数相加
Help on built-in function sum in module builtins:
sum(iterable, /, start=0)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.