1.Python的元組和字典
1.1元組
元組:就像是一個使用括號的列表根时。
============================================================
>>> a
(1, 2, 3, 4, 5, 6)
>>> print(a)
(1, 2, 3, 4, 5, 6)
>>> print(a[3])
4
>>> d = (1,23,45,67,76)
>>> d
(1, 23, 45, 67, 76)
>>> f = ('e','r')
>>> f
('e', 'r')
>>> g = d+f
>>> print(g)
(1, 23, 45, 67, 76, 'e', 'r')
>>> print(5*f)
('e', 'r', 'e', 'r', 'e', 'r', 'e', 'r', 'e', 'r')
>>> print(d,g)
(1, 23, 45, 67, 76) (1, 23, 45, 67, 76, 'e', 'r')
==============================================================
元組上面的知識點跟列表一模一樣炭菌,只有一點區(qū)別,就是元組一旦創(chuàng)建就不能在做改動了。目前就涉及到兩個函數(shù)(append函數(shù)和delete函數(shù))
1.2 字典
字典(dict , 是dictinoary的縮寫。也叫map 乏奥,映射)也是一堆東西的組合。字典與列表和元組不同的地方是字典中的每一個元素都有一個鍵(key)和一個對應(yīng)的值(value)亥曹。
---------------------------------------------------------------------------------------------------------
the_number = {1: 'a',2:'b',3:'c' }
>>> the_number
{1: 'a', 2: 'b', 3: 'c'}
>>> print(the_number[2])
b
>>> del the_number[2] ? ? ? ? ? ? ? ? ? ? ? ?// ? 刪除key等于 2 的整個內(nèi)容
>>> print(the_number)
{1: 'a', 3: 'c'}
>>> the_number[3]='g' ? ? ? ? ? ? ? ? ? ? ? ??// ?替換value的值 ? 用對應(yīng) 的key?
>>> print(the_number)
{1: 'a', 3: 'g'}
------------------------------------------------------------------------------------------------------------
使用字典與使用列表和元組類似邓了,但是你不能用 ?+ ?運算來把兩個字典連在一起,因為這樣連接字典沒有意義媳瞪。
****** ? ? ******** ? ?********** ? ?********* ? ?*********** ? ?******** ? ?******* ? ?*********** ? ?********* ? ?*****
1.3用Python 來畫圖
forward(**):向前畫
backward(**):向后畫
left(**):左轉(zhuǎn)
right(**):右轉(zhuǎn) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // ?** ? 為數(shù)字
up():抬起畫筆 ? ?→ ?此時運動不出現(xiàn)線條
down():放下畫筆 ? → 此時運動出現(xiàn)線條
clear():清除畫板驶悟,不回到初始點
reset():重置,回到初始點
------------------------------------------------------
>>> t.reset()
>>> t.backward(100)
>>> t.up()
>>> t.right(90)
>>> t.forward(30)
>>> t.left(90)
>>> t.down()
>>> t.forward(100)
---------------------------------------------------------
============================================
>>> import turtle ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// 用Python 中的 import 引入 turtle 模版
>>> t = turtle.Pen() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// ?調(diào)用turtle模版中的Pen函數(shù) ?注意:Pen函數(shù)中的P 一定要大寫
>>> t.forward(50) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//向前50個像素
>>> t.left(90) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //指針左轉(zhuǎn)90度
>>> t.forward(50) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
>>> t.right(90) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//指針右轉(zhuǎn)90度
>>> t.forward(50) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
============================================