PS3曾让索尼亏损10亿美元!吉田:当时觉得PS要完蛋了
·
1.1 Python是什么?
Python是一种高级、解释型的编程语言,由吉多·范罗苏姆在1991年创建。它以简洁的语法和强大的功能,成为当今最受欢迎的编程语言之一。
Python的独特优势:
✅ 语法简洁,接近自然语言
✅ 丰富的第三方库和框架
✅ 跨平台兼容性强
✅ 活跃的社区支持
✅ 应用领域广泛
1.2 Python能做什么?
Web开发:Django、Flask框架
数据分析:Pandas、NumPy、Matplotlib
人工智能:TensorFlow、PyTorch
自动化脚本:系统管理、文件处理
网络爬虫:Requests、BeautifulSoup
游戏开发:Pygame
2.1 安装Python
步骤1:下载Python
访问Python官网(python.org)
下载最新版本(推荐Python 3.8+)
Windows用户勾选"Add Python to PATH"
步骤2:验证安装
打开命令行(CMD或终端),输入:
bash
python --version
或
bash
python3 --version
2.2 选择开发工具
IDLE:Python自带的简易IDE
VS Code(推荐):轻量级,功能强大
PyCharm:专业Python IDE
Jupyter Notebook:适合数据分析和学习
3.1 Hello World程序
创建文件 :
python
# 这是一个注释
print("Hello, World!")
print("欢迎来到Python世界!")
# 计算并输出结果
result = 3 + 5
print("3 + 5 =", result)
# 打印多个值
name = "小明"
age = 20
print("姓名:", name, "年龄:", age)
3.2 运行程序
bash
# 在命令行中运行
python hello.py
输出结果:
text
Hello, World!
欢迎来到Python世界!
3 + 5 = 8
姓名: 小明 年龄: 20
4.1 变量与数据类型
python
# 基本数据类型
name = "李华" # 字符串
age = 18 # 整数
height = 1.75 # 浮点数
is_student = True # 布尔值
# 打印类型信息
print(type(name)) #
print(type(age)) #
print(type(height)) #
print(type(is_student))#
# 多重赋值
x, y, z = 1, 2, 3
4.2 基本运算
python
# 算术运算
a = 10
b = 3
print("加法:", a + b) # 13
print("减法:", a - b) # 7
print("乘法:", a * b) # 30
print("除法:", a / b) # 3.333...
print("整除:", a // b) # 3
print("取余:", a % b) # 1
print("幂运算:", a ** b) # 1000
4.3 字符串操作
python
# 字符串基础
text = "Python编程"
print("字符串长度:", len(text))
print("大写:", text.upper())
print("小写:", "HELLO".lower())
# 字符串格式化
name = "张三"
score = 95
print(f"{name}的成绩是{score}分") # f-string(推荐)
print("{}的成绩是{}分".format(name, score)) # format方法
5.1 条件判断
python
# if-elif-else结构
score = 85
if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 60:
print("及格")
else:
print("不及格")
# 简化写法
result = "通过" if score >= 60 else "不通过"
print("考试结果:", result)
5.2 循环结构
python
# for循环
print("数字1-5:")
for i in range(1, 6):
print(i)
# 遍历列表
fruits = ["苹果", "香蕉", "橙子"]
for fruit in fruits:
print("我喜欢吃" + fruit)
# while循环
count = 3
while count > 0:
print(f"倒计时: {count}")
count -= 1
print("开始!")
6.1 列表(List)
python
# 创建列表
numbers = [1, 2, 3, 4, 5]
names = ["Alice", "Bob", "Charlie"]
# 列表操作
print("第一个元素:", numbers[0]) # 1
print("最后一个元素:", numbers[-1]) # 5
print("切片:", numbers[1:3]) # [2, 3]
# 修改列表
numbers.append(6) # 添加元素
numbers.insert(0, 0) # 插入元素
numbers.remove(3) # 删除元素
print("修改后的列表:", numbers)
6.2 字典(Dictionary)
python
# 创建字典
student = {
"name": "王小明",
"age": 20,
"major": "计算机科学",
"grades": [85, 92, 78]
}
# 访问字典
print("姓名:", student["name"])
print("年龄:", student.get("age"))
# 修改字典
student["age"] = 21
student["email"] = "wang@example.com"
# 遍历字典
for key, value in student.items():
print(f"{key}: {value}")
7.1 定义和调用函数
python
# 定义函数
def greet(name):
"""向指定的人打招呼"""
return f"你好,{name}!"
def calculate_area(length, width):
"""计算矩形面积"""
area = length * width
return area
# 调用函数
message = greet("李华")
print(message)
area_result = calculate_area(5, 3)
print(f"矩形面积: {area_result}")
# 函数默认参数
def introduce(name, age, city="北京"):
print(f"我是{name},{age}岁,来自{city}")
introduce("张三", 25) # 使用默认城市
introduce("李四", 30, "上海") # 指定城市
8.1 文件操作
python
# 写入文件
with open("diary.txt", "w", encoding="utf-8") as file:
file.write("2024年学习日记
")
file.write("今天开始学习Python!
")
# 读取文件
with open("diary.txt", "r", encoding="utf-8") as file:
content = file.read()
print(content)
# 逐行读取
with open("diary.txt", "r", encoding="utf-8") as file:
for line in file:
print(line.strip()) # 去除换行符
8.2 异常处理
python
try:
# 可能出错的代码
number = int(input("请输入一个数字: "))
result = 10 / number
print(f"结果是: {result}")
except ValueError:
print("错误:请输入有效的数字!")
except ZeroDivisionError:
print("错误:不能除以零!")
except Exception as e:
print(f"发生未知错误: {e}")
else:
print("计算成功完成!")
finally:
print("程序执行完毕")
9.1 21天学习计划
第一周:基础入门
第1-2天:环境搭建、基础语法
第3-4天:数据类型、流程控制
第5-7天:函数、文件操作
第二周:核心进阶
第8-10天:面向对象编程
第11-12天:常用模块学习
第13-14天:错误处理
第三周:项目实战
第15-21天:完成2-3个小项目
9.2 推荐练习项目
计算器:实现四则运算
通讯录:添加、删除、查找联系人
天气查询:调用API获取天气信息
简易爬虫:抓取网页信息
9.3 学习资源推荐
官方文档:docs.python.org
在线教程:菜鸟教程、廖雪峰Python教程
实践平台:LeetCode、牛客网
视频课程:B站优质Python教学视频
10.1 新手常见错误
python
# 1. 缩进错误
# 错误:
if True:
print("hello") # 缺少缩进
# 正确:
if True:
print("hello")
# 2. 变量名错误
# 错误:
1st_name = "张三" # 变量名不能以数字开头
# 正确:
first_name = "张三"
# 3. 类型错误
# 错误:
age = "18"
result = age + 1 # 字符串不能与数字相加
# 正确:
age = int("18") # 转换为整数
result = age + 1
10.2 调试技巧
使用 输出中间结果
使用VS Code的调试功能
阅读错误信息,理解问题所在
使用try-except捕获异常
学习Python就像学习一门新技能,实践是最好的老师。记住这些建议:
每天坚持:哪怕只有30分钟
动手实践:不要只看不写
从小开始:从简单项目积累信心
善用资源:遇到问题先搜索
加入社区:与其他学习者交流
今日行动清单:
安装Python和VS Code
编写并运行Hello World程序
尝试修改代码,观察不同效果
Python的世界充满无限可能,从今天开始,用代码创造你的数字奇迹!记住,每个Python高手都曾是零基础的新手。开始编码吧!Ὠ;
1.1 Python是什么?
Python是一种高级、解释型的编程语言,由吉多·范罗苏姆在1991年创建。它以简洁的语法和强大的功能,成为当今最受欢迎的编程语言之一。
Python的独特优势:
✅ 语法简洁,接近自然语言
✅ 丰富的第三方库和框架
✅ 跨平台兼容性强
✅ 活跃的社区支持
✅ 应用领域广泛
1.2 Python能做什么?
Web开发:Django、Flask框架
数据分析:Pandas、NumPy、Matplotlib
人工智能:TensorFlow、PyTorch
自动化脚本:系统管理、文件处理
网络爬虫:Requests、BeautifulSoup
游戏开发:Pygame
2.1 安装Python
步骤1:下载Python
访问Python官网(python.org)
下载最新版本(推荐Python 3.8+)
Windows用户勾选"Add Python to PATH"
步骤2:验证安装
打开命令行(CMD或终端),输入:
bash
python --version
或
bash
python3 --version
2.2 选择开发工具
IDLE:Python自带的简易IDE
VS Code(推荐):轻量级,功能强大
PyCharm:专业Python IDE
Jupyter Notebook:适合数据分析和学习
3.1 Hello World程序
创建文件 :
python
# 这是一个注释
print("Hello, World!")
print("欢迎来到Python世界!")
# 计算并输出结果
result = 3 + 5
print("3 + 5 =", result)
# 打印多个值
name = "小明"
age = 20
print("姓名:", name, "年龄:", age)
3.2 运行程序
bash
# 在命令行中运行
python hello.py
输出结果:
text
Hello, World!
欢迎来到Python世界!
3 + 5 = 8
姓名: 小明 年龄: 20
4.1 变量与数据类型
python
# 基本数据类型
name = "李华" # 字符串
age = 18 # 整数
height = 1.75 # 浮点数
is_student = True # 布尔值
# 打印类型信息
print(type(name)) #
print(type(age)) #
print(type(height)) #
print(type(is_student))#
# 多重赋值
x, y, z = 1, 2, 3
4.2 基本运算
python
# 算术运算
a = 10
b = 3
print("加法:", a + b) # 13
print("减法:", a - b) # 7
print("乘法:", a * b) # 30
print("除法:", a / b) # 3.333...
print("整除:", a // b) # 3
print("取余:", a % b) # 1
print("幂运算:", a ** b) # 1000
4.3 字符串操作
python
# 字符串基础
text = "Python编程"
print("字符串长度:", len(text))
print("大写:", text.upper())
print("小写:", "HELLO".lower())
# 字符串格式化
name = "张三"
score = 95
print(f"{name}的成绩是{score}分") # f-string(推荐)
print("{}的成绩是{}分".format(name, score)) # format方法
5.1 条件判断
python
# if-elif-else结构
score = 85
if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 60:
print("及格")
else:
print("不及格")
# 简化写法
result = "通过" if score >= 60 else "不通过"
print("考试结果:", result)
5.2 循环结构
python
# for循环
print("数字1-5:")
for i in range(1, 6):
print(i)
# 遍历列表
fruits = ["苹果", "香蕉", "橙子"]
for fruit in fruits:
print("我喜欢吃" + fruit)
# while循环
count = 3
while count > 0:
print(f"倒计时: {count}")
count -= 1
print("开始!")
6.1 列表(List)
python
# 创建列表
numbers = [1, 2, 3, 4, 5]
names = ["Alice", "Bob", "Charlie"]
# 列表操作
print("第一个元素:", numbers[0]) # 1
print("最后一个元素:", numbers[-1]) # 5
print("切片:", numbers[1:3]) # [2, 3]
# 修改列表
numbers.append(6) # 添加元素
numbers.insert(0, 0) # 插入元素
numbers.remove(3) # 删除元素
print("修改后的列表:", numbers)
6.2 字典(Dictionary)
python
# 创建字典
student = {
"name": "王小明",
"age": 20,
"major": "计算机科学",
"grades": [85, 92, 78]
}
# 访问字典
print("姓名:", student["name"])
print("年龄:", student.get("age"))
# 修改字典
student["age"] = 21
student["email"] = "wang@example.com"
# 遍历字典
for key, value in student.items():
print(f"{key}: {value}")
7.1 定义和调用函数
python
# 定义函数
def greet(name):
"""向指定的人打招呼"""
return f"你好,{name}!"
def calculate_area(length, width):
"""计算矩形面积"""
area = length * width
return area
# 调用函数
message = greet("李华")
print(message)
area_result = calculate_area(5, 3)
print(f"矩形面积: {area_result}")
# 函数默认参数
def introduce(name, age, city="北京"):
print(f"我是{name},{age}岁,来自{city}")
introduce("张三", 25) # 使用默认城市
introduce("李四", 30, "上海") # 指定城市
8.1 文件操作
python
# 写入文件
with open("diary.txt", "w", encoding="utf-8") as file:
file.write("2024年学习日记
")
file.write("今天开始学习Python!
")
# 读取文件
with open("diary.txt", "r", encoding="utf-8") as file:
content = file.read()
print(content)
# 逐行读取
with open("diary.txt", "r", encoding="utf-8") as file:
for line in file:
print(line.strip()) # 去除换行符
8.2 异常处理
python
try:
# 可能出错的代码
number = int(input("请输入一个数字: "))
result = 10 / number
print(f"结果是: {result}")
except ValueError:
print("错误:请输入有效的数字!")
except ZeroDivisionError:
print("错误:不能除以零!")
except Exception as e:
print(f"发生未知错误: {e}")
else:
print("计算成功完成!")
finally:
print("程序执行完毕")
9.1 21天学习计划
第一周:基础入门
第1-2天:环境搭建、基础语法
第3-4天:数据类型、流程控制
第5-7天:函数、文件操作
第二周:核心进阶
第8-10天:面向对象编程
第11-12天:常用模块学习
第13-14天:错误处理
第三周:项目实战
第15-21天:完成2-3个小项目
9.2 推荐练习项目
计算器:实现四则运算
通讯录:添加、删除、查找联系人
天气查询:调用API获取天气信息
简易爬虫:抓取网页信息
9.3 学习资源推荐
官方文档:docs.python.org
在线教程:菜鸟教程、廖雪峰Python教程
实践平台:LeetCode、牛客网
视频课程:B站优质Python教学视频
10.1 新手常见错误
python
# 1. 缩进错误
# 错误:
if True:
print("hello") # 缺少缩进
# 正确:
if True:
print("hello")
# 2. 变量名错误
# 错误:
1st_name = "张三" # 变量名不能以数字开头
# 正确:
first_name = "张三"
# 3. 类型错误
# 错误:
age = "18"
result = age + 1 # 字符串不能与数字相加
# 正确:
age = int("18") # 转换为整数
result = age + 1
10.2 调试技巧
使用 输出中间结果
使用VS Code的调试功能
阅读错误信息,理解问题所在
使用try-except捕获异常
学习Python就像学习一门新技能,实践是最好的老师。记住这些建议:
每天坚持:哪怕只有30分钟
动手实践:不要只看不写
从小开始:从简单项目积累信心
善用资源:遇到问题先搜索
加入社区:与其他学习者交流
今日行动清单:
安装Python和VS Code
编写并运行Hello World程序
尝试修改代码,观察不同效果
Python的世界充满无限可能,从今天开始,用代码创造你的数字奇迹!记住,每个Python高手都曾是零基础的新手。开始编码吧!Ὠ;
更多推荐
所有评论(0)