公司动态

Python学习第二部分

📅 2026/8/17 21:54:02
Python学习第二部分
一、turtle模块1、介绍turtle海龟Python内置的一个标准模块提供了绘制线、圆以及其它形状的函数使用该模块可以创建图形窗口在图形窗口中通过简单重复动作直观地绘制界面与图形。turtle的使用三个方面①创建窗口 ②设置画布 ③绘制图形turtlr模块文档查看搜索 — Python 3.10.20 文档2、例子import turtle as t t.pensize(4) t.hideturtle() #隐藏画笔 t.colormode(255) t.color((255,155,192),pink) t.setup(840,500) t.speed(10) #鼻子 t.pu() #抬起画笔 t.goto(-100,100) t.pd() t.seth(-30) t.begin_fill() a0.4 for i in range(120): if 0i30 or 60i90: aa0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: aa-0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.seth(90) t.fd(25) t.seth(0) t.fd(10) t.pd() t.pencolor(255,155,192) t.seth(10) t.begin_fill() t.circle(5) t.color(160,82,45) t.end_fill() t.pu() t.seth(0) t.fd(20) t.pd() t.pencolor(255,155,192) t.seth(10) t.begin_fill() t.circle(5) t.color(160,82,45) t.end_fill() #头 t.color((255,155,192),pink) t.pu() t.seth(90) t.fd(41) t.seth(0) t.fd(0) t.pd() t.begin_fill() t.seth(180) t.circle(300,-30) t.circle(100,-60) t.circle(80,-100) t.circle(150,-20) t.circle(60,-95) t.seth(161) t.circle(-300,15) t.pu() t.goto(-100,100) t.pd() t.seth(-30) a0.4 for i in range(60): if 0i30 or 60i90: aa0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: aa-0.08 t.lt(3) t.fd(a) t.end_fill() #耳朵 t.color((255,155,192),pink) t.pu() t.seth(90) t.fd(-7) t.seth(0) t.fd(70) t.pd() t.begin_fill() t.seth(100) t.circle(-50,50) t.circle(-10,120) t.circle(-50,54) t.end_fill() t.pu() t.seth(90) t.fd(-12) t.seth(0) t.fd(30) t.pd() t.begin_fill() t.seth(100) t.circle(-50,50) t.circle(-10,120) t.circle(-50,56) t.end_fill() #眼睛 t.color((255,155,192),white) t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-95) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color(black) t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() t.color((255,155,192),white) t.pu() t.seth(90) t.fd(-25) t.seth(0) t.fd(40) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color(black) t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() #腮 t.color((255,155,192)) t.pu() t.seth(90) t.fd(-95) t.seth(0) t.fd(65) t.pd() t.begin_fill() t.circle(30) t.end_fill() #嘴 t.color(239,69,19) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(-100) t.pd() t.seth(-80) t.circle(30,40) t.circle(40,80) #身体 t.color(red,(255,99,71)) t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-78) t.pd() t.begin_fill() t.seth(-130) t.circle(100,10) t.circle(300,30) t.seth(0) t.fd(230) t.seth(90) t.circle(300,30) t.circle(100,3) t.color((255,155,192),(255,100,100)) t.seth(-135) t.circle(-80,63) t.circle(-150,24) t.end_fill() #手 t.color((255,155,192)) t.pu() t.seth(90) t.fd(-40) t.seth(0) t.fd(-27) t.pd() t.seth(-160) t.circle(300,15) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(0) t.pd() t.seth(-10) t.circle(-20,90) t.pu() t.seth(90) t.fd(30) t.seth(0) t.fd(237) t.pd() t.seth(-20) t.circle(-300,15) t.pu() t.seth(90) t.fd(20) t.seth(0) t.fd(0) t.pd() t.seth(-170) t.circle(20,90) #脚 t.pensize(10) t.color((240,128,128)) t.pu() t.seth(90) t.fd(-75) t.seth(0) t.fd(-180) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color(black) t.pensize(15) t.fd(20) t.pensize(10) t.color((240,128,128)) t.pu() t.seth(90) t.fd(40) t.seth(0) t.fd(90) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color(black) t.pensize(15) t.fd(20) #尾巴 t.pensize(4) t.color((255,155,192)) t.pu() t.seth(90) t.fd(70) t.seth(0) t.fd(95) t.pd() t.seth(0) t.circle(70,20) t.circle(10,330) t.circle(70,30) t.done()二、中文分词1、分词方法英文分词split方法中文分词2、中文分词 - jieba中文分词将一个汉字序列切分成一个一个单独的词也就是说将连续的字序列按照一定的规范重新组合成词序列的过程。作用将用户输入的中文语句或语段拆成若干汉语词汇。3、分词模式①精确模式试图将句子最精确地切开适合文本分析②全模式把句子中所有的可以成词的词语都扫描出来, 速度非常快不能解决歧义③搜索引擎模式在精确模式的基础上对长词再次切分提高召回率。④paddle模式利用PaddlePaddle深度学习框架训练序列标注双向GRU网络模型实现分词。4、jieba模块的常用方法5、例子三、集合1、介绍集合类型数学中的集合是指具有某种特定性质的对象汇总而成的集体其中构建集合的这些对象称为该集合的元素。集合的元素特征2、创建集合1使用{}创建集合2使用set()创建集合3⚠️注意3、集合的常见操作4、集合运算四、字典1、介绍映射在数学中设A、B是两个非空集合若按某个确定的对应法则f使集合A中的任意一个元素x在集合B中都有唯一确定的元素y与之对应则称f为从集合A到集合B的一个映射。字典Python唯一的内建映射类型且可存储任意类型对象。在编程中通过“键”查找“值”的过程称为映射。字典是典型的映射类型其中存放的是多个键值对。2、原则字典的键遵守的两个原则1键唯一键是不可变类型。可以用数字字符串或元组充当不可以用列表2值可以取任何数据类型3、字典元素的访问与修改使用“字典变量[键]”的形式可以查找字典中与“键”对应的值使用赋值运算符可以动态修改字典中的值。4、通过操作键增加元素5、字典的常见操作字典类型也支持使用保留字in来判断某个键是否存在于字典中如果键存在则返回True否则返回False。6、字典的遍历方法1遍历key值2遍历value值3遍历key值value值4遍历字典项7、例子五、列表、元组、集合、字典总结