标签:形式 变量 highlight 检测 集合类 zip asio color 翻转
print(abs(-1))
print(all([12,‘asds‘,345])) print(all(‘‘)) #特例 若参数为空也返回True print(all((0,))) print(all([]))
print(any([1231, 0])) print(any([0]))
print(bin(3)) # 10进制转化为二进制 print(hex(15)) # 10进制转化为16进制 print(oct(15)) # 10 进制转化为8进制
print(bool(0)) print(bool(‘‘)) #可以是空列表空元组 print(bool(None))
name = ‘大白‘ print(bytes(name, encoding = ‘utf - 8‘)) # utf-8 一个中文 = 3 个字节
name = ‘大白‘ print(bytes(name, encoding = ‘utf - 8‘).decode(‘utf-8‘))
print(chr(1223))
print(dir(dict))
print(divmod(10, 3)) 10/3 商3余1
dic_str1 = "{‘name‘: ‘alex‘}" print((eval(dic_str1))) print(type(eval(dic_str1))) print(type(dic_str1))
express = ‘1 + 1‘ print(eval(express))
print(hash(‘shfduqwhfkwsajdfh9237498231‘)) print(hash(‘5211314‘)) print(hash(‘5211314safhciwsafhwiofhdajskdhjioas;fhdasiodcjasodfacxasd‘)) name = ‘jinling‘ print(hash(name)) print(hash(name)) name = ‘dabai‘ print(hash(name))
print(isinstance(1, int)) print(isinstance(‘abc‘, str)) print(isinstance([], list)) print(isinstance([], tuple))
name = ‘天青色等烟雨而我在等你‘ print(globals()) def test(): age = ‘18‘ print(locals()) test()
age_dic = {‘alex3‘: 18, ‘liu1‘: 17, ‘jinling2‘: 16} print(max(age_dic.values())) #指定比较values print(max(age_dic)) #默认比较的是key, 一位一位的比较
l1 = [ (5, ‘e‘), (1, ‘l‘), (3, ‘o‘), (2, ‘v‘) ] print(max(l1))
print(list(zip([‘l‘, ‘o‘, ‘v‘, ‘e‘], [1, 2, 3, 4])))
p = {‘name‘: ‘alex‘, ‘age‘: 18, ‘gender‘: ‘none‘} print(list(zip(p.keys(), p.values())))
dic = {‘age‘: 18, ‘age2‘: 10} print(max(dic)) #默认比较的是key print(max(dic.values())) #比较的是key,但不知道是哪个key的 print(max(zip(dic.values(), dic.keys())))
people = [ {‘name‘: ‘dabai‘, ‘age‘: 21}, {‘name‘: ‘jinling‘, ‘age‘: 19}, {‘name‘: ‘liu‘, ‘age‘: 20}, {‘name‘: ‘sb‘, ‘age‘: 100} ] print(max(people, key=lambda dic: dic[‘age‘])) #自己写函数规则
li = [3, 5, 9, 7] l2 = [] while len(li) > 1: a = min(li) l2.append(a) li.remove(a) l2.append(li[0]) print(l2)
print(chr(97)) print(ord(‘a‘))
print(pow(2, 2)) #2**3 print(pow(2, 2, 3)) #2**3 % 3
l1 = [1, 2, 3, 4, 5] print(list(reversed(l1)))
print(round(4.6))
print(set(‘jinling‘))
l = ‘jinling‘ s1 = slice(3, 5) print(l[s1]) s2 = slice(2, 5, 2) print(l[s2]) print(s2.start) print(s2.stop) print(s2.step)
l = [3, 2, 15, 7] print(sorted(l))
people = [ {‘name‘: ‘dabai‘, ‘age‘: 21}, {‘name‘: ‘jinling‘, ‘age‘: 19}, {‘name‘: ‘liu‘, ‘age‘: 20}, {‘name‘: ‘sb‘, ‘age‘: 100} ] print(sorted(people, key = lambda dic: dic[‘age‘]))
name_dic = { ‘liuwenhao‘: 10000, ‘jinling‘: 9999, ‘dabai‘: 9998 } print(sorted(name_dic)) #默认比较key值 print(sorted(name_dic, key = lambda key: name_dic[key])) print(sorted(zip(name_dic.keys(), name_dic.values())))
l1 = [1, 2, 4, 5, 6] print(sum(l1))
print(type(‘love‘))
def test(): msg = ‘月下门筒喟叹昨夜太平长安‘ print(locals()) print(vars()) #没有参数时,效果和locals一样 test() print(vars(int)) #把int下所有方法存成字典的形式
module_name = ‘test‘ m = __import__(module_name) m.say_hai() #使用test中的方法
标签:形式 变量 highlight 检测 集合类 zip asio color 翻转
原文地址:https://www.cnblogs.com/dabai123/p/11144740.html