python 学习笔记

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)]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值