python内置函数

2021-05-29 01:01

阅读:717

标签:全局变量   返回   ted   oca   names   item   简单的   内置函数   lse   

# print()
# input()
# len()
# type()
# int()
# str()
# list()
# tuple()
# dict()
# set()
# float()
# id()

# avg = sum(l) / len(l) #计算平均值
# print(avg)
# print( max(l) )
# print(min(l))
# print( round(avg,3) ) #保留几位小数

# print(any( [False,False,False,True] )) #list里面只要有一个为true,就返回true
# print(all([True,True,True,True])) #list里面必须都为true,就返回true
# print(chr(65)) #把阿斯克码转成对应的值
# print(ord(‘A‘) )#把值转成阿斯克码
# print(bin(10)) #10进制转2进制
# print(int("1010",base=2))#2进制转10进制的
# print(int("12",base=8))#8进制转10进制的
# print(oct(10)) #10进制转8进制的
# print(hex(10)) #10进制转16进制
# print(int("a",base=16)) #16进制转进制的

# print(divmod(10,3)) #取商和余数的
# print(divmod(10,2)) #取商和余的

name = "abc"
def test():
age = 19
addr = "beijing"
print(locals())
print(globals())
# test()
# locals()#取当前函数里面的所有局部变量
# globals()#取全局变量
usernames = [‘admin‘,‘test‘,‘dev‘]
passwrods = [89,100,61]
# passwrods2 = [123,456,789]
#
# for u,p,z in zip(usernames,passwrods,passwrods2):
# print(u,p,z)
# #
# print(list(zip(usernames,passwrods)))
# print(dict(zip(usernames,passwrods)))
import pprint
# print(l)

# pprint.pprint(str(l))

s = ‘346343477‘
# print(‘‘.join(sorted(s)))#排序


d = {‘admin‘: 89, ‘test‘: 100, ‘dev‘: 61}

def x(l):
return l[1]
# print(d.items())
# print( sorted(d.items(),key=x,reverse=True) )
print(
sorted(d.items(),key=lambda x:x[1],reverse=True)
)

# test = lambda x:x*3
# print(test(3))
#lambda 只能定义一些简单的功能

# map()
# filter()

# l2 = [ str(i) for i in l]
# def func(x):
# x = str(x)
# if len(x)==1:
# return ‘00‘+x
# elif len(x)==2:
# return ‘0‘+x
# return x
# l2 = list(map(func,l)) #循环帮你调函数,保存结果到一个list里面
#
# # l = [1,2,3,4,43,634,63,4634,63,636,23]
# # l2 = list( map(lambda x:str(x),l) )
# #
#
# # l2 = list(map(str,l))
# print(l2)

python内置函数

标签:全局变量   返回   ted   oca   names   item   简单的   内置函数   lse   

原文地址:https://www.cnblogs.com/dengjinjiao/p/14775272.html


评论


亲,登录后才可以留言!