学习python第二天
海龟绘图:
import turtle # 海龟绘图
turtle.showturtle() # showturtle展示箭头
turtle.write('搞起') # write写入字符串
turtle.forward(300) # forword向前移动
turtle.color('red') # coclor改变颜色,初始颜色为黑色。
turtle.left(90) # left向左移动箭头角度,rignt向右移动箭头角度。
turtle.forward(300)
turtle.goto(0,50) # goto移动到某个点
turtle.goto(0,0)
turtle.penup() # penup抬起
turtle.goto(0,300)
turtle.pendown() # pendown放下
turtle.goto(50,50)
turtle.circle(100) # circle画圆
奥运五环:
import turtle
turtle.width(10) # width加粗
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)
turtle---海龟绘图
https://docs.python.org/zh-cn/3/library/turtle.html#module-turtle
对象:每个对象由标识(id),类型(type),值(value)组成。变量位于:栈内存 对象位于:堆内存。
a=3 #把3赋值给a a 3 id(3) #3的id 140712710166240 id(a) #a的id 140712710166240 type(3) #3的类型 <class 'int'> type(a) #a的类型 <class 'int'> print(a) 3
标识符区分大小写,第一个字符必须为字母,单下划线,可以通过输入help()查看关键字,避免使用关键字。
max=2 Max=4 _max=6 max 2 Max 4 _max 6 help() Welcome to Python 3.8's help utility! If this is your first time using Python, you should definitely check out the tutorial on the Internet at https://docs.python.org/3.8/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". help> keywords Here is a list of the Python keywords. Enter any keyword to get more help. False class from or None continue global pass True def if raise and del import return as elif in try assert else is while async except lambda with await finally nonlocal yield break for not
divmod(a,b)是可以把一个除法的商和余给打印出来。
divmod(16,3) (5, 1)
googol=10*100。
round(value)四舍五入。
round(4.3) 4

浙公网安备 33010602011771号