《Python基礎教程》 ( )

2021-08-30 10:54:54 字數 1237 閱讀 6187

這部分主要是《python基礎教程》的讀書筆記。用python已經一段時間了,基礎部分沒問題,這裡主要列出閱讀過程中看到的以前不會的東西。

x = input("x: ")
x = range(6)

x.count(1)

insert操作

numbers = [1, 2, 3, 5, 6, 7]

numbers.insert(3, 'four')

remove操作

x = range(6)

x.remove(1)

reverse操作

x = range(6)

x.reverse()

sort操作

x.sort(key=len, reverse=true)
s.replace(a, b)
strip函式:除去兩側的空格字串

k in dict
fromkeys

{}.fromkeys(range(2))
items: 將字典項以列表方式返回

iteritems: 返回迭代器物件(比items更加高效)

keys: 將字典中的鍵以列表形式返回

iterkeys: 返回針對鍵的迭代器

pop: 彈出乙個指定鍵的鍵值對

d.pop('x')
popitem: 彈出乙個隨機的鍵值對

d.popitem()
update: 將新字典的新增到舊字典中,相同的鍵值進行覆蓋

d.update(newdict)
if not condition:

crash program

for name, age in zip(names, ages)
>>> map(str, range(6))

>>> def add(x, y):

... return x + y

...>>> reduce(add, [1, 3, 5, 7, 9])

25

python基礎教程

乙個簡單的客戶機 import socket s socket.socket host socket.gethostname port 1234 s.bind host,port s.listen 5 while true c,addr s.accept print got connection f...

Python基礎教程

本教程不包括python的安裝,ide採用spyder pytho2.7 1.print pow 2,3 8 print 2 3 8這裡pow函式表示乘方,與 功能相同。2.abs 10 10abs函式用來求乙個數的絕對值。3.round 0.6 1.0 round 0.4 0.0round函式將浮...

Python 基礎教程

python由guido van rossum於1989年底發明,第乙個公開發行版發行於1991年。像perl語言一樣,python 源 同樣遵循 gpl gnu general public license 協議。本教程主要針對python 2.x版本的學習,如果你使用的是python 3.x版本...