python学习笔记四(注意知识点)

1
注释
单行注释#
多行注释’’’ ‘’’

2
选择性语句
if 。。else for

3循环语句
3.1 while
while也可以与else结合使用
(VScode终端调试终止循环使用“CTRL+C”键)
递归较常使用while

3.2 for
主要是用来遍历/循环 序列或者集合,字典
也可与else搭配使用

a = [[‘apple’,‘orange’,‘banana’,‘grape’],(1,2,3)]
for x in a:
# print(x)
for y in x:
print(y)
# print(y,end=’’)不换行
else:
print(‘fruit is gone’)

for x in range(10,0,-2):
print(x,end=’ | ')

a = [[‘apple’,‘orange’,‘banana’,‘grape’],(1,2,3)]
for x in a:
if ‘banana’ in x:
break #跳出最外层循环(此处else和for配对)
# print(x)
for y in x:
if y==‘orange’:
break #仅跳出本层for循环
print(y)
# print(y,end=’’)不换行
else:
print(‘fruit is gone’)

4开发要求
会写代码,非常容易
高性能,封装性(可复用),抽象
直白
美与不美
高追求

5 python项目的组织结构
包 > 模块 > 类(函数 ,变量)

6.一行不超过80个字符

7.包和模块是不会被重复导入的

避免循环导入

8:函数
print()

a = 1.12385
result = round(a,2)
print(result)

作用:
a:功能性
b:隐藏细节
c:避免编写重复的代码
d:组织代码 自定义函数

python函数解释
def funcname(parameter_list):
pass
a:其中parameter_list参数列表可以没有
b:函数有return value;如果没有return,系统默认为None

参数
a.必须参数
b.关键字参函数
c.默认参数(默认参数要置于必须参数之后)

发布了22 篇原创文章 · 获赞 0 · 访问量 440

猜你喜欢

转载自blog.csdn.net/qq_36956082/article/details/85399819
今日推荐