python-first基礎

#python基礎
一##math模塊
Dir(math)
常用操作:
Math.pi log10 math exp
Decimal
內置對象字符串
Ord 八進制
Bin 二進制
“”和一個’’的區別在哪裏?
講解:s=‘python book’
s[::2]=‘pto ok’ 從頭到尾遍歷,長度是二
s[::-1]當爲-1的時候,倒敘輸出
index(" 一個元素")返回的是一個下標
獲取長度用len()
isdigit()函數是一個布爾函數,返回的是一個bool值
不明白的用help(),比如help(str。isdigit)
split分割函數 返回的是一個list列表
eg:a = “i love python” a.split(" “)
[‘i’, ‘love’, ‘python’]
join函數可以修改回去
“-”.join(lst)
‘i-love-python’
str的內置方法很多dir(str)來解決
格式化輸出的幾種方式
“I like {0} and {1}”.format(“python”, “physics”)
“I like %s and %s” % (“python”, “physics”)
I like {0:10} and {1:>15}”.format(“python”, “physics”)
‘I like python and physics’
“I like {0:^10} and {1:^15}”.format(“python”, “physics”)
'I like python and physics ’
“I like {0:.2} and {1:^15.3}”.format(“python”, “physics”)
'I like py and phy ’
在字符串前邊加上r+u、分別代表原始字符串和unicode字符串
strip()函數去除\r\n\t split函數是看用哪個分開
list裏邊可以包含很多種類的元素
s = “abcdef”
s[0] = “m”
在這裏邊是不可以的
append函數是添加
可以用insert函數
remove函數
pop函數
clear函數
可以直接點sort函數 sorted函數呦區別,一個是改變原列表一個是不改變
list可以通過下表直接修改值
list[::-1] 和list[:-1]這個相同效果
在切片中第4和6個元素的話,需要【3:6】
嵌套列表 類似於多維數組

		   元組合字典
		   tuple()
		   tuple不可修改
		   字典用dict,用key 和value 
		   	in是代表在不在裏邊的一個要求
		   	"shanghai" in city_phone
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章