2024年1月30日发(作者:)
Python期末复习知识点整理
1. 数据类型
- 整数(int)
- 浮点数(float)
- 字符串(str)
- 列表(list)
- 元组(tuple)
- 字典(dict)
- 布尔值(bool)
2. 控制结构
条件语句
if condition:
do something
elif condition:
do something
else:
do something
循环语句
while循环
while condition:
do something
for循环
for item in iterable:
do something
3. 函数
定义函数的语法:
def function_name(parameters):
do something
return something
4. 字符串操作
字符串拼接
str1 + str2
字符串格式化
"{} {}".format(arg1, arg2)
字符串切片
str[]
5. 列表操作
列表索引
list[index]
列表切片
list[]
列表添加元素
(item)
列表删除元素
(item)
del list[index]
6. 字典操作
字典访问
dict[key]
字典添加或修改键值对
dict[key] = value
字典删除键值对
del dict[key]
7. 文件操作
文件读取
f = open(file_path, 'r')
content = ()
文件写入
f = open(file_path, 'w')
(content)
()
8. 异常处理
try:
do something
except ExceptionType:
exception handling
以上是Python期末复习的一些重要知识点,希望对你的复习有所帮助!
本文发布于:2024-01-30 11:11:40,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170658430020027.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |