-
1.python 简介(蟒蛇)
-
前身是abc语言,由荷兰,吉多.范罗苏姆编写python诞生于1989.12.25,在1991年 版本1.0问世
,在2000人工智能复苏后逐渐兴起。目前主要的与python就业方向有爬虫、数据分析、web(需求少)、自动化运维测试。 -
2.数据类型:
-
数据就是大量的信息
-
int 整数 1、-1、0
-
float 浮点型 0.38
-
str 字符串 “ hello world”
-
bool 布尔类型 True / False
-
tuple 元组 是不可变的list (1,2,3,‘付强’)
-
list 列表 【1,2,‘付强’】
-
dict 字典 { ‘key’:“value”,“key2”:“value2” }
-
set 集合
-
complex 复数
-
3.变量:可以改变的量------起名字
-
规则:
-
必须是字母、数字、下划线组合
-
数字不能开头
-
起名字不能是关键字
-
多个单词用 _ 连接
-
见名知意
-
大小写敏感
-
price != Price
-
查询关键字
`
import keyword
print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else',
'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or',
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']`
-4.运算符:
- 算术运算符 :a=10 b=20
- a+b=30 a-b=-10 a*b=200 b/a=2 9%4=1(取模返回除法之后的余数) 9//4=2(取整除向下整除) -9//4=-3
- 比较运算符: < <= > >= == != 结果:bool
- 逻辑运算符: and(并且,与) or (或者) not(非 ) 结果:bool
- and ( 女的 有钱的 )
- or (米饭 馒头)
- not (不要丑的)
- in not in
- is is not
# product_name = "高端男士潮流保暖大花裤衩"
# print("男士裤衩保暖花边" not in product_name)
- 5.turtle库
- 导入
- import turtle as t 以下的代码turtle可以用t代替
画布canvas
turtle.screensize(canvwidth=None, canvheight=None, bg=None),参数分别为画布的宽(单位像素), 高, 背景颜色。
如:turtle.screensize(800,600, "green")
turtle.screensize() #返回默认大小(400, 300)
turtle.setup(width=0.5, height=0.75, startx=None, starty=None),参数:width, height: 输入宽和高为整数时, 表示像素; 为小数时, 表示占据电脑屏幕的比例,(startx, starty): 这一坐标表示矩形窗口左上角顶点的位置, 如果为空,则窗口位于屏幕中心。
如:turtle.setup(width=0.6,height=0.6)
turtle.setup(width=800,height=800, startx=100, starty=100)
turtle.pencolor():没有参数传入,返回当前画笔颜色,传入参数设置画笔颜色,可以是字符串如"green", "red",也可以是RGB 3元组。
turtle.forward(distance) 向当前画笔方向移动distance像素长度
turtle.backward(distance) 向当前画笔相反方向移动distance像素长度
turtle.right(degree) 顺时针移动degree°
turtle.left(degree) 逆时针移动degree°
turtle.goto(x,y) 将画笔移动到坐标为x,y的位置
turtle.circle() 画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆
setx( ) 将当前x轴移动到指定位置
sety( ) 将当前y轴移动到指定位置
setheading(angle) 设置当前朝向为angle角度
[python绘图](https://www.cnblogs.com/mxk123/p/11653250.html)
t.pensize(4) # 设置画笔的大小
t.speed(10) # 设置画笔速度为10 【1、10】整数数值越大越快
t.pu() # 提笔
t.pd() # 下笔