1、画一个五环
import turtle
turtle.width(5)
turtle.color('black')#设置画笔颜色
turtle.circle(50)#设置圆半径
turtle.penup()#画笔抬起
turtle.goto(120,0)#画笔移动到xx坐标点
turtle.pendown()#画笔放下
turtle.color('red')
turtle.circle(50)
turtle.penup()
turtle.goto(240,0)
turtle.pendown()
turtle.color('yellow')
turtle.circle(50)
turtle.penup()
turtle.goto(60,-50)
turtle.pendown()
turtle.color('blue')
turtle.circle(50)
turtle.penup()
turtle.goto(180,-50)
turtle.pendown()
turtle.color('green')
turtle.circle(50)
2、行连接符 \

类似于加号连接符

a='hello \
world'
b='hello python'
print(a)
2.5、变量

弱类型语言

3、对象

对象有标识(对象名),类型,值(value)构成
使用id来获取对象的地址

<class ‘int’>

a=333
b=id(a)
print(b)#2925387727824
print(type(a))#<class 'int'>
4、引用

变量也称之为对象的引用,变量存储的就是对象的地址,变量通过地址引用独享
变量位于栈中,对象位于堆中

ptyhon是动态类型语言。变量不需要显示声明类型,根据变量引用的对象,python解释器自动确定数据类型
python是强类型语言 (需要确定类型)

5、标识符

变量,函数,类,模块的名字

大小写敏感

双下划綫开头和结尾的名称有特殊含义

python 画圆 填充 python怎么给圆环填色_赋值

6、链式赋值及系列解包赋值
  • 链式赋值
a=b=123
print(a)#123
print(b)#123

系列解包赋值
系列数据赋值给对应相同个数的变量

a,b,c=4,5,6
print(a)#4
print(b)#5
print(c)#6
7、常量

不支持常量,没有语法规则限制改变一个常量
常量还是约定大写
常量逻辑上不可修改,但修改也并没有什么问题
声明,赋值上和 变量没有什么不同

MAX='hello world'
print(MAX)#hello world
MAX='hello python'
print(MAX)#hello python
8、基本内置数据类型

整型
浮点型
布尔型
字符串型
complex复数类型 varn=5+6j

9、运算符
  • ** 求幂(乘方)
a=2**3
print(a)#8
  • 同时得到商和余数

divmod(parm1,parm2)

a,b=divmod(32,3)#32/3
print(a,b)#10,2
10、隐式及显示数据转换(转型)

同java

a=3.1245
b=int(a)
print(b)#3

c=True
d=3
e=d+1
print(e)

float转换浮点型
round()可以四舍五入,不改变原值,产生新对象

a=333
b=float(a)
d=3.56
c=round(d)
print(b)
print(c)#4
print(d)#3.56

str(3)
float(3)
bool转型直接用int(),float(),bool()

11、增强型赋值运算符

+=
*-
%=
**=
之类

12、时间的表示

unix时间:全数字,从1970.1.1开始
通过time.time()获得当前时刻的毫秒值,并且是个浮点数
需要import time

import time
print(time.time())#1630668319.0760617
13、布尔

True,Flase,注意首字母大写
逻辑运算符
or
and
not

14、比较运算

==
!=

<

=
<=

15、同一运算符

is:判断两个标识符是不是引用同一个对象
is not :判断两个标识符是不是引用不同对象

==用于判断应用变量引用对象的值是否相等,默认调用对象的__eq__()方法
is运算符效率更好

a=b=34
c=34
d=35
print( a is b))#True
print(b is c))#True
print(c is d)#False
print( a==b))#True
print( a==c))#True
print( a==d)#False
print( a.__eq__(b))#True
16、字符串
  • 字符串的本质是字符序列
  • python的字符串是不可变的,无法对原字符串做任何修改,但是,可以将字符串的一部分复制到新建的字符串,达到看起来修改的效果
  • python不支持单字符类型,单字符也是作为一个字符串使用
  • 单引号或双引号包含,双引号里面可以包单引号,单引号也可以包含双银行
  • 三引号‘’’可以创建多个字符串
a='hello'
b=''' name="zhangsan" address="beijing" '''
print(a)#hello
print(b)#name="zhangsan" address="beijing"

三个引号还可以保留格式(预格式文本),也是大字符串,只要前面有变量接受就不会当做注释里是用

17、空字符串和len()函数
a=''
b=''' name="zhangsan" address="beijing" '''
print(len(a))#0
print(len(b))#35
18、转义字符

\ +特殊字符

(在行位)续行符

python 画圆 填充 python怎么给圆环填色_python_02

19、字符串拼接



如果+号两边类型不同,则会抛出异常
可以将多个字面字符串直接放到一起实现拼接
‘aa’ ‘bb’

20、字符串复制

使用*号进行字符串复制

a='hello'*3
print(a)#hellohellohello
21、不换行打印

通过参数end=‘任意字符串’实现末尾添加任何内容

print('aa',end='$$$' )#aa$$
22、从控制台读取字符串

类似于JavaScript的confirm()函数

name=input('请输入名字')
print(name)
23、pep8格式化

通过缩进来替代了部分{ }的场景
默认4个空格缩进
格式化快捷键 ctrl+alt+L