Python编程基础记一次课堂笔记:for循环&函数编写
程序员文章站
2022-06-25 18:44:12
...
Python编程基础,for循环、嵌套for循环(99乘法表) 、函数有参、无参:
list_1 = [1, 2, 3, 4, 5]
i = 0
for item in list_1:
print("这是一种第三种方式的复杂版:{}".format(list_1[i]) ,end=" ")
i += 1
for item1 in list_1:
print("\n第二种方式遍历序列类型的值:{}".format(item1))
for item2 in range(len(list_1)):
print("第三种方式遍历序列类型的值:{}".format(list_1[item2]),end=" ")
# 元组解包
dict_1 = {"a1": "a2", True: "False", "age": 19}
for key, value in dict_1.items():
print("\nkey={},value={}".format(key, value))
# function 方法体 == 函数
def func(name):
for item in name:
print(item)
func(list_1)
# function 返回return关键字
def multi(a,b):
"""
:param a:
:param b:
:return:
"""
return a*b
print("两个数的乘积:{}".format(multi(25,10)))
# func.__doc__查看方法体的注释
print(multi.__doc__)