码迷,mamicode.com
首页 > 其他好文 > 详细

内置函数2

时间:2019-10-15 21:16:56      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:compile   文件   als   pre   长度   val   缓存   简单   strip   

# import time
# for i in range(1,101,2):
# time.sleep(0.1)
# char_num=i//2
# per_str="\r%s%% :%s\n"%(i,‘*‘*char_num) \
# if i==100 else "\r%s%% :%s" % (i,‘*‘*char_num)
# print(per_str,end="",flush=True)#fluch把内容输出到流文件,不需要缓存


# eval((print(1+2+3+4)))#先执行再返回,并且返回结果
# print(exec(1+2+3+4))#实际计算了,但是没有返回值


# eval适合处理有结果的,简单计算,明确你要执行的代码是什么
# evec适合处理流程-----简单流程控制
# eval能明确知道你要执行的代码是什么


# code=‘‘‘for i in range(10):
# print(i*‘*‘)
# ‘‘‘
# exec(code)
# code1="1+2+3+4"
# compile2=compile(code1,‘‘,‘eval‘)
# print(eval(compile2))


# code3=‘name=input("请输入你的名字:")‘
# 执行前name变量不存在
# compile8=compile(code3,‘‘,‘single‘)
# print(exec(compile8))#执行时显示交互命令,提示输入
# print(name)#执行后name有值
# print(abs(-5))#求绝对值
#
# print(round(3.1415926,3))#保留3位小数
# print(pow(2,3))#做幂运算
# print(pow(2,3,2))#再这里表示的是2*3/2的余数


# #bytes字节转换
# print(bytes("你好",encoding="GBK"))#unicode转变成GBK
# print(bytes("你好",encoding="utf-8"))#unicode转换为utf-8
#
#
# #字节数组
# b_array=bytearray("你好",encoding="utf-8")
# print(b_array)

# #关于repr()函数的用法
# print(repr("1"))
# print(repr(1))
# print("你好%r"%"egg")#这个r实际就是调用了repr的方法


#
# print(all([12,3,‘‘,5]))#判断是否有空内容,有任何一个空它就是false
# print(any(["",[],12,2,23,8]))#有一个空格就是ture

# #zip的用法,返回一个迭代器,也叫拉链
# l=[1,2,3]
# dict={"k1":1,"k2":2,"k3":3}
# l1=["a","b","c"]
# for i in zip(l,l1,dict):
# print(i)


# filter的用法
# def L_odd(n):
# return n%2==1
# g1=filter(L_odd,[1,2,3,4,6,4,5,6])#意思就是在这里取满足条件的数字
# for i in g1:
# print(i)
# g=[i for i in [1,2,3,4,6,4,5,6] if i%2==1]
# for i in g:
# print(i)


#
# def LLL(list):
# if type(list)==int:
#
# return str(list).strip()and list
# g=filter(LLL,[" " , 12,3,4,5,6])
# L=list(g)
# print(L)
# for i in g:
# print(i)
#
# from math import sqrt
# def find_number(num):
# ret=sqrt(num)
# return ret%1==0
# g = filter(find_number, range(1, 101))#执行filter结果后的集合《==原来的集合
# #执行的前后并不会改变原来的值
# for i in g:
# print(i)



#关于map的用法
# ret=map(abs,[-1,-2,-3])#map使用的前后,元素的个数不变,元素的值发生了改变,返回了执行后的值
# for i in ret:
# print(i)



#关于sorted的用法
# l=[1,-12,4,55,5,5,5,5]
# l.sort(key=abs)#在这里加上abs,意思就是按照绝对值排序
# print(l)
#排序后原来列表的顺序保留,不改变原来的列表
# print(sorted(l))

l=["grsegres","grseg",[1,2,3],"fffa"]
ret=sorted(l,key=len)#在这里是按照长度排序
print(ret)


内置函数2

标签:compile   文件   als   pre   长度   val   缓存   简单   strip   

原文地址:https://www.cnblogs.com/648071634com/p/11679995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!