Python 教学大纲

Power By 赵文瑄

课程简介

这个课程是为了介绍 Python 编程语言,并且通过实践和例子来帮助学生理解 Python 的基础概念。

第一天:Python 基础

Python 简介

  • Python 是什么?
  • Python 的应用领域
  • Python 的优势和特点

安装 Python

  • 下载和安装 Python
  • 安装和使用 Python 的集成开发环境(IDE),如 PyCharm、VSCode 等

Python 的基本语法

  • Python 的变量和数据类型
    • 整数、浮点数、字符串、列表、元组、字典等
1
2
3
4
5
6
7
8
9
10
11
12
# 整数
x = 10
# 浮点数
y = 3.14
# 字符串
s = "Hello, Python"
# 列表
lst = [1, 2, 3, 4, 5]
# 元组
tup = (1, 2, 3)
# 字典
dic = {"name": "John", "age": 25}
  • Python 的运算符
    • 算术运算符、比较运算符、逻辑运算符等
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 算术运算符
print(10 + 5) # 加法
print(10 - 5) # 减法
print(10 * 5) # 乘法
print(10 / 5) # 除法

# 比较运算符
print(10 > 5) # 大于
print(10 < 5) # 小于
print(10 == 5) # 等于
print(10 != 5) # 不等于

# 逻辑运算符
print(True and False) # 与
print(True or False) # 或
print(not True) # 非

Python 的控制结构

  • 条件语句(if-elif-else)
1
2
3
4
5
6
7
x = 10
if x > 0:
print("x is positive")
elif x < 0:
print("x is negative")
else:
print("x is zero")
  • 循环语句(for 和 while)
1
2
3
4
5
6
7
8
9
# for 循环
for i in range(5):
print(i)

# while 循环
i = 0
while i < 5:
print(i)
i += 1

实践:Python 的第一个程序

  • “Hello, World!” 程序
1
print("Hello, World!")
  • 简单的算术运算
1
2
3
4
5
6
7
8
9
# 输入两个数字
x = int(input("Enter a number: "))
y = int(input("Enter another number: "))

# 输出它们的和、差、积、商
print("The sum is:", x + y)
print("The difference is:", x - y)
print("The product is:", x * y)
print("The quotient is:", x / y)

课后练习

  • 编写一个可以接受用户输入的程序,并输出 “Hello, {用户输入}!”
1
2
name = input("Enter your name: ")
print("Hello, " + name + "!")
  • 编写一个程序,输入两个数字,并输出它们的和、差、积、商
1
2
3
4
5
6
7
x = int(input("Enter a number: "))
y = int(input("Enter another number: "))

print("The sum is:", x + y)
print("The difference is:", x - y)
print("The product is:", x * y)
print("The quotient is:", x / y)

参考资料

下节预告

在下一节课中,我们将深入了解 Python 的函数和模块。