内置函数

'''
内置函数,不需要导入任何模块就可以使用的函数
'''
print(bytearray('长大的',encoding='utf-8'))
'''
转成字节
'''
print(callable(abs(1)))
'''
是否可以执行
'''
print(chr(int(101)))
'''
将一个数字转换成ascill码里面的字符
chr一般和ord一起用,
ord是将ascill里面的字符转换成数字,使用场景多为动态验证码
'''
print(ord(str('a')))
li=['a','b','c']
for i in li:
print(i)
for i in enumerate(li,0):
print(i)
'''
enumerate,额外增加一列,进行序列的增加
'''

'''
eval使用场景,对于电子表格里面的东西,
里面都是字符串,如果是普通方法,首先会进行split,
eval会直接识别这些
'''
print(eval('6*8'))
'''
filter,map
filter用来过滤的
map用来做条件的
'''
s=[11,22,33,44]
for i in s:
i=i+100
print(i)

new_s=map(lambda x:x+100,s)
'''
map会循环后面的参数,每循环一次,
就会将前面的函数执行一次,将执行的结果赋给返回值
'''
print(new_s)
l=list(new_s)
print(l)
print('s',s)
'''
filter就会进行过滤,最终会得到新的数据,是对元数据的修改
'''
def func(a):
a = int()
if a > 10:
return True
else:
return False
print(filter(func,s))
p=filter(func,s)
print('p',list(p))
'''
hash会作为字典的key用的
'''
print(hex(100))
reversed(s)
print(s)
print(round(9,1))
x=[1,2,3]
y=[4,5,6]
print(zip(x,y))
'''
open中的b模式使用场景主要包括、
在Python3中采用字符读
tell表示指针的位置,tell是用字节来读的
seek会指定指针,seek之前的数据不会被读写,如果出现seek插在如中文的中间,
就会出现乱码的情况,会读写失败
read会读取seek指针后面的数据
truncate会进行切片,会直接修改文件,没有返回值
'''
f=open('test.log','w')
f.write(
'爱情sdfdf''hao'
)
f.close()
p=open('test.log','r+')
print(p.read(4))
print(p.tell())
print(p.seek(7))
print(p.read())
print(p.truncate(6))
print('j',p.read())
p.close()



bytearray(b'\xe9\x95\xbf\xe5\xa4\xa7\xe7\x9a\x84')
False
e
97
a
b
c
(0, 'a')
(1, 'b')
(2, 'c')
48
111
122
133
144
<map object at 0x0055F790>
[111, 122, 133, 144]
s [11, 22, 33, 44]
<filter object at 0x0055FDB0>
p []
0x64
[11, 22, 33, 44]
9
<zip object at 0x0056A5A8>
爱情sd
6
7
dfhao
6
j





posted on 2016-02-11 12:13  卷土重来  阅读(166)  评论(0编辑  收藏  举报

导航