1.hasattr(object,name):用来判断object是否含有name属性
2.pass代表空语句 不进行任何操作,一般用作占位语句。
3.encode的作用是将unicode编码转换成其他编码的字符
串
4.decode的作用是将其他编码的字符串转换成unicode编码
5.file变量表示为当前文件路径(包含文件名)
import os
os.path.dirname(__file__) #表示当前文件所在目录,如果文件是以相对路径运行则返回空字符,如果是绝对路径返回完整路径
os.path.abspath(__file__) #返回当前文件的规范化绝对路径
os.path.join('home','test') #进行路径拼接返回'home/test'
6.python中split函数用法
str1 = "I am learning"
str2 = "I*am*learning"
l = str1.split(' ')
ll = str1.split('*')
s = str2.split('*')
print(l)
输出结果
['I','am','learning']
['I am Learning']
['I','am','learning']
7.future模块
from __future__ import unicode_literals #可以在旧版本python中使用新版本unicode相关特性
8.python3中支持unicode编码所以在
sys模块中删除了setdefaultencoding属性
9.set集合是一个无序不重复元素集,基本功能包括关系测试和消除重复元素,还支持& | -操作
x=set('hello')
y=set('hot')
print(x)
print(y)
#output
{'e','h','l'}
{'o','h','t'}
10.floor()函数
floor(x)方法返回不大于x的最大整数(向下取整)。必须先导出math模块
import math
math.floor(12.1) #output 12
11.zip()函数
x = [1, 2, 3]
y = [4, 5, 6]
xy = zip(x,y)
print(xy)
#output
[(1,4),(2,5),(3,6)]
x = [1, 2, 3]
y = [4, 5, 6, 7]
xy = zip(x, y)
print(xy)
#output
[(1, 4), (2, 5), (3, 6)]
x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
xyz = zip(x, y, z)
u = zip(*xyz)
print (u)
#output
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]