day1-3
``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
#turtle基础知识
import turtle
turtle.showturtle()
turtle.write("高旗")
turtle.forward(300)#向前走300
turtle.color("red")#修改颜色
turtle.goto(0,50)#到坐标点(0,50)
turtle.left(90)#向左转90度
turtle.forward(300)
turtle.goto(0,0)
turtle.penup()#抬起笔
turtle.goto(0,50)
turtle.pendown()#落下笔
turtle.goto(0,50)
turtle.goto(50,50)
turtle.circle(100)#画一个半径为100的圆
#turtle 奥运五环练习
turtle.width(10)
turtle.color("blue")
turtle.circle(50)
turtle.penup()
turtle.goto(120,0)
turtle.pendown()
turtle.color("black")
turtle.circle(50)
turtle.penup()
turtle.goto(240,0)
turtle.pendown()
turtle.color("red")
turtle.circle(50)
turtle.penup()
turtle.goto(60,-50)
turtle.pendown()
turtle.color("yellow")
turtle.circle(50)
turtle.penup()
turtle.goto(180,-50)
turtle.pendown()
turtle.color("green")
turtle.circle(50)
#二、一些运算符号
#/是浮点数除法
#//是整除
#%是取余数
#divmod是既得到商,也得到余数
#三、时间的表示
import time
time.time()#到现在一共多长时间,小数点前是秒,小数点后是微秒
a=int(time.time())
#小练习,计算折线图,并计算起始点和初始点的距离
import math
x1,y1=100,100
x2,y2=100,-100
x3,y3=-100,-100
x4,y4=-100,100
turtle.penup()
turtle.goto(x1,y1)
turtle.pendown()
turtle.goto(x2,y2)
turtle.goto(x3,y3)
turtle.goto(x4,y4)
distance=math.sqrt((x1-x4)*2+(y1-y4)*2)
#在进行比较的时候,==用于比较数值是否相等,is用于比较对象是否相同
#用三个’或者“可以创建多个字符串
c='''name=”zcs“ weight="70" income="20000"'''
#不换行的打印
print("aaa",end="\t")
print("bbb",end="*")
print("ccc",end="\n")
#从控制台读取字符串
myname=input("请输入名字:")
#str字符串
str(123)#变为字符串类型
b='dfbgwqerthfgn'
b[3]#字符串的提取,从0开始从左往右开始
b[-1]
#replace实现字符串的修改
b=b.replace('d','高')
#切片
b[3:5]
b[3:5:2]#起始点,终点,步长。包头不包尾
#小练习
#”to be or not to be“字符串倒序输出
c="to be or not to be"
c[::-1]
#"sxtsxtsxtsxtsxt"输出所有的s
d="sxtsxtsxtsxtsxt"
d[::3]
#split and join函数
c.split()#默认按照空格进行拆分
c.split("be")
d=["sxt100","sxt200","sxt300"]
"*".join(d)
''.join(d)
li=[]
for i in range(10):
li.append("sxt")
print(li)
#字符串驻留机制
#包含_那么id相同
a="abc_d"
b="abc_d"
a==b
a is b
c="abc#"
d="abc#"
c==d#is比较的是id,==比较的是value
c is d
"b" in d#判断b这个字符串是否在d里面
#format格式,两种表示方法
a="名字是:{0},年龄:{1}"
a.format("张翰",20)
a="名字是:{0},年龄:{1},{0}是个帅哥"#占位符可以重复引用
b="名字是:{name},年龄:{age}"
b.format(name="张翰",age=20)
c=b.format(name="Tom",age=19)
#填充与对齐
#^<>分别表示居中,左对齐,右对齐,后面跟着宽度,:后面跟着填充的字符(默认是空格)
b="名字是:{name},年龄:{age:*^20}"
b.format(name="张翰",age=20)
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````