python 内置函数
1. abs()
abs(x) Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.
# 返回一个数的绝对值,如果是复数,则返回它的大小
1 >>> number2 = -12.02 2 >>> print(abs(number2)) 3 12.02 4 >>> number1 = 12 5 >>> print(abs(number1)) 6 12
2. all(iterable)
1 # Return True if all elements of the iterable are true (or if the iterable is empty). Equivalent to: 2 def all(iterable): 3 for element in iterable: 4 if not element: 5 return False 6 return True
# 字面翻译,判断一个迭代器是否存在空值,如果存在空值,则为FALSE。类似与条件判断符号 AND, 全真才为真。
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 if __name__ == '__main__': 5 'functions is test all() ' 6 list1 = list(range(10)) 7 'append space in list1' 8 list1.append("") 9 'print it' 10 for x in list1: 11 print(x) 12 temp = all(list1) 13 if temp: 14 print("这个列表没有 空值") 15 else: 16 print("这个列表存在空值")
3. any(iterable)
1 # Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to: 2 def any(iterable): 3 for element in iterable: 4 if element: 5 return True 6 return False
# 判断 一个迭代器中是否存在真值,如果存在,则返回 True, 类似与条件判断符号 OR
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 if __name__ == '__main__': 5 'functions is test any() ' 6 'number1 是 集合类型' 7 number1 = set() 8 temp1 = any(number1) 9 if temp1: 10 print("数据已清空,还没有更新") 11 else: 12 number1.add('The Book is important ! ') 13 print(number1)
4. bool()
1 class bool([x]) 2 3 Return a Boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True.
The bool class is a subclass of int (see Numeric Types — int, float, complex). It cannot be subclassed further. Its only instances are False and True (see Boolean Values).
# 判断 一个参数的真假,一般是 NONE,{},[],0,"" 为假。
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 if __name__ == '__main__': 5 'functions is test bool()' 6 string1 = input(prompt='Please your zhanghao:') 7 if bool(string1): 8 print('The zhanghao is %s' % string1) 9 else: 10 print('Please your zhanghao:')
5. bytes()
1 class bytes([source[, encoding[, errors]]]) 2 Return a new “bytes” object, which is an immutable sequence of integers in the range 0 <= x < 256. bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior.
我除了胖点,再没啥优点。
浙公网安备 33010602011771号