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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章