Python 學習筆記 3

2021-09-23 20:19:10 字數 1956 閱讀 8844

import turtle

顯示當前的畫筆在**(筆起始位置在(0,0))

turtle.showturtle()
寫一句話

(text,font=("微軟雅黑",20,"bold"))  #字型大小及形狀

turtle.write("welcome to python",font=("微軟雅黑",20,"bold"))

向箭頭方向前進300個畫素點

turtle.forward(300)
向右轉(起始方向為右)

turtle.right(90)
字型顏色

turtle.color("red")
畫圓

turtle.circle(r)

# r為半徑

抬筆,放筆動作

turtle.penup()  #抬起筆

turtle.goto(50,50) #用一直線連線兩點

turtle.pendown()#放下筆

填充

示例:將乙個圓填充為藍色

turtle.begin_fill()

turtle.color("blue")

t.circle(100)

turtle.end_fill()

筆的粗細與畫圖速度

turtle.pensize(n)

turtle.speed(n)

#n位數字,改變n的大小即可改變筆粗細與速度

隱藏箭頭

turtle.hideturtle()
表示繪製完畢,顯示影象

turtle.done()
接下來就是:

**例項:畫乙個奧運五環

import turtle

turtle.pensize(10)

turtle.speed(10)

turtle.penup()

turtle.goto(-80,0)

turtle.pendown()

turtle.color("blue")

turtle.circle(60)

turtle.penup()

turtle.goto(0,0)

turtle.pendown()

turtle.color("black")

turtle.circle(60)

turtle.penup()

turtle.goto(80,0)

turtle.pendown()

turtle.color("red")

turtle.circle(60)

turtle.penup()

turtle.goto(-40,-70)

turtle.pendown()

turtle.color("yellow")

turtle.circle(60)

turtle.penup()

turtle.goto(40,-70)

turtle.pendown()

turtle.color("green")

turtle.circle(60)

turtle.penup()

turtle.goto(-200,-200)

turtle.pendown()

turtle.color("red")

turtle.write("北京歡迎您",font=("微軟雅黑",80,"bold"))

turtle.hideturtle()

turtle.done()

python學習筆記3

1 字串的格式化操作 format variable format 是格式的樣式,variable 是要被格式化的變數 format 有如下幾種形式 o 將數值轉換為八進位制 x 將數值轉換為十六進製制 d 整數轉換符號 s 字串轉換符號 如下 o 100 144 o 100 加入乙個 號可輸出標準...

python 學習筆記3

2014 10 23 三種內建的資料結構 列表 元組和字典 list len list list.sort 修改列表本身,而不是返回乙個修改後的列表 列表時可變的,字串不可變 for item in list 遍歷 del list 0 刪除專案,自動補齊。print語句的結尾的逗號消除列印的換行符...

Python學習筆記3

條件和迴圈語句 生成隨機數的函式,此處說明一下,python是通過乙個方程來產生隨機數的,所以這些隨機數並不是真正隨機的,產生他們的方式叫做偽隨機。載入模組,本人理解模組類似c裡的庫,模組 module 含有可供其他程式使用的 的檔案,這些模組通常是按照一定的相關性進行組織的,載入模組使用 impo...