1.常用的开发环境2.程序基本格式3.海龟画图4.海龟画图制作奥运五环5.使用行连接符6.对象7.标识符8.Python标识符命名规则9. 变量
1.常用的开发环境- IDLEPycharmwingIDEEclipseIpython
Python使用缩进来控制层次
Python区分大小写
注释
行注释:行前面加#号
#print(“a")
段注释:在段落前后加```
'''
print("a")
print("b")
print("c")
'''
海龟画图基本操作
import turtle #导入 turtle 模块
turtle.showturtle() #显示箭头
turtle.write("高淇") #写字符串
turtle.forward(300) #前进 300 像素
turtle.color("red") #画笔颜色改为 red
turtle.left(90) #箭头左转 90 度
turtle.forward(300)
turtle.goto(0,50) #去坐标(0,50)
turtle.goto(0,0)
turtle.penup() #抬笔。这样,路径就不会画出来
turtle.goto(0,300)
turtle.pendown() #下笔。这样,路径就会画出来
turtle.circle(100)
4.海龟画图制作奥运五环
import turtle
turtle.width(10) #线条宽度
turtle.color("blue") #线条颜色
turtle.circle(50) #圆的大小
turtle.color("black")
turtle.penup() #抬笔
turtle.goto(120,0) #移动至此坐标点
turtle.pendown() #落笔
turtle.circle(50)
turtle.color("red")
turtle.penup()
turtle.goto(240,0)
turtle.pendown()
turtle.circle(50)
turtle.color("yellow")
turtle.penup()
turtle.goto(60,-50)
turtle.pendown()
turtle.circle(50)
turtle.color("green")
turtle.penup()
turtle.goto(180,-50)
turtle.pendown()
turtle.circle(50)
运行结果:
为方便阅读,可将 放在比较长的行结束的位置,Python仍视为多行为一行
a=[10,20,30,40,50,60,70,80,90,100] b=[10,20, 30,40,50, 60,70,80,90,100]6.对象
对象的本质:一个内存块,拥有特定的值,支持特定类型的相关操作
7.标识符使用Python帮助系统查看关键字
help() keyword8.Python标识符命名规则
| 名称 | 规则 | 例子 |
|---|---|---|
| 模块和包名 | 全小写字母。多个单词之间用下划线 | math,os,sys。 |
| 函数名 | 全小写字母。多个单词之间用下划线 | phone,my_name。 |
| 类名 | 首字母大写。多个单词时,每个单词第一个字母大写,其余全小写 | 如、MyPhone、MyClass、Phone。 |
| 常量名 | 全大写字母。多个单词用下划线隔开 | SPEED、MAX_SPEED。 |
- 变量在使用前必须进行初始化(赋值)
a=3
- 删除变量
a=3 del a



