目录
画小猪佩奇
python的历史
1982年圣诞节开始孕育,在1992年2月正式诞生。之后出现了python 1.x python 2.x python 3.x。
如果对Python的历史感兴趣,可以阅读名为《Python简史》的网络文章。
python 的优缺点
优点:
①简单明了,容易上手,个人感觉学python比学c要简单一些;
②开放源代码,丰富的社区,特别在机器学习和数据分析领域;
③解释型语言;
④对两种主流的编程范式,分别是面向对象编程,函数式编程;
⑤代码简洁,代码可读性高;
缺点:
①执行的效率低,明显比C,C++的速度慢;
②代码无法加密,但是现在大多公司售卖的服务,对于加密的要求不高;
③开发的时候的Web框架很多。
python的应用领域
Web应用后端开发、云基础设施建设、DevOps、网络数据采集(爬虫)、自动化测试、数据分析、机器学习 等领域 有着广泛的应用
Python样例
输出python 之 禅
import this
画出一个播放器的模样
画小猪佩奇
#画几何图形
import turtle
turtle.pensize(100) #笔的大小,可以根据大小,呈现出实心或空心
turtle.pencolor('red') #笔的颜色
#画个正方形
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.pensize(4) #笔的大小,可以根据大小,呈现出实心或空心
turtle.pencolor('blue')
#画个三角形
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
#画出一个播放器的样子
turtle.mainloop() #显示绘图窗口
#画小猪佩奇
from turtle import *
def nose(x,y):
#nose
penup()
goto(x,y) #将海龟移动到指定的坐标
pendown()
setheading(-30) #
#设置海龟的方向
#(0--东 90--北 180--西 270--南)
begin_fill()
a = 0.4
for i in range(120):
if (0 <= i < 30) or (60 <= i < 90):
a = a + 0.08
left(3) #向左转三3度
forward(a) #前进a
else:
a = a - 0.08
left(3)
forward(a)
end_fill()
penup()
setheading(90)
forward(25)
setheading(0)
forward(10)
pendown()
#设置画笔的颜色(红,绿,蓝)
pencolor(255,255,192)
setheading(10)
begin_fill()
circle(5)
color(160,82,45)
end_fill()
penup()
setheading(0)
forward(20)
pendown()
pencolor(255,155,192)
setheading(10)
begin_fill()
circle(5)
color(160,82,45)
end_fill()
def head(x,y):
color((255,155,192), "pink")
penup()
goto(x,y)
setheading(0)
pendown()
begin_fill()
setheading(180)
circle(300, -30)
circle(100, -60)
circle(80, -100)
circle(150, -20)
circle(60, -95)
setheading(161)
circle(-300, 15)
penup()
goto(-100, 100)
pendown()
setheading(-30)
a = 0.4
for i in range(60):
if (0 <= i < 30) or (60 <= i < 90):
a = a + 0.08
left(3)
forward(a)
else:
a = a - 0.08
left(3)
fd(a)
end_fill()
def eyes(x,y):
color((255,155,192),"white")
penup()
setheading(90)
forward(-20)
setheading(0)
forward(-95)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
color((255,155,192), "white")
penup()
setheading(90)
forward(-25)
setheading(0)
forward(40)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
def ears(x,y):
color((255,155,192), "pink")
penup()
goto(x,y)
pendown()
begin_fill()
setheading(100)
circle(-50, 50)
circle(-10,120)
circle(-50,54)
end_fill()
penup()
setheading(90)
forward(-12)
setheading(0)
forward(30)
pendown()
begin_fill()
setheading(100)
circle(-50,50)
circle(-10,120)
circle(-50,56)
end_fill()
def cheek(x,y):
color((255,155,192))
penup()
goto(x,y)
pendown()
setheading(0)
begin_fill()
circle(30)
end_fill()
def mouth(x,y):
color(23,69,19)
penup()
goto(x,y)
pendown()
setheading(-80)
circle(30,40)
circle(40,80)
#参数设置
def setting():
pensize(4)
hideturtle() #隐藏海龟turtle
colormode(255)
color((255,155,192), "pink")
setup(840,500)
speed(10)
def main():
setting()
nose(-100,100)
head(-69,167)
ears(0,160)
eyes(0,140)
cheek(80,10)
mouth(-20,30)
done()
if __name__ == '__main__':
main()