1. 编程环境
Python版本
- 了解Python的版本,如Python 2.x和Python 3.x的区别。
IDLE操作
- 新建文件:在IDLE中创建一个新的Python文件。
- 保存文件:将代码保存到文件中。
- 代码缩进:Python使用缩进来表示代码块。
- 代码注释:使用
#进行单行注释。 - 程序运行:在IDLE中运行Python程序。
其他编程环境
- 了解除了IDLE之外的其他编程环境,如PyCharm、VSCode等。
2. 编程基础
print()语句
print("Hello, World!")
双引号和单引号
name = "Kimi"
greeting = 'Hello, ' + name
字符串及数值类型转换
age_str = "25"
age_int = int(age_str)
age_float = float(age_str)
input()语句
user_input = input("Enter your name: ")
print("Hello,", user_input)
变量的命名和使用
x = 10
y = 20
sum = x + y
保留字
# 错误示例
# if = 5 # 'if'是保留字,不能用作变量名
3. turtle库
导入库文件
import turtle
画布设置
turtle.setup(600, 400)
turtle.bgcolor("white")
画笔设置
turtle.pencolor("red")
turtle.pensize(5)
到达指定坐标
turtle.goto(100, 100)
画点
turtle.dot(50)
画圆
turtle.circle(50)
画笔操作
turtle.forward(100)
turtle.backward(50)
turtle.left(90)
turtle.right(90)
turtle.pendown()
turtle.penup()
4. 运算符
算术运算符
a = 10
b = 5
sum = a + b
difference = a - b
product = a * b
quotient = a / b
赋值运算符
c = a
d = b
关系运算符
is_equal = (a == b)
is_not_equal = (a != b)
is_greater = (a > b)
is_less = (a < b)
逻辑运算符
is_and = (a > b) and (c == a)
is_or = (a < b) or (c != a)
is_not = not (a == b)
运算符的优先顺序
result = 2 + 3 * 4 # 先乘后加
5. 计算思维
能编写顺序执行的程序
print("Step 1")
print("Step 2")
print("Step 3")
能分析简单逻辑运算的结果并使用结果
if (a > b) and (c == a):
print("Both conditions are true")
能分析比较运算的结果并使用结果
if (a < b):
print("a is less than b")
else:
print("a is not less than b")