-
- Returns 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.
Example:print(abs(5))
Output:
print(abs(-5.23))
print(abs(-5+6j))5
5.23
7.810249675906654 -
- Return True if all elements of the iterable are true or if the iterable is empty. Otherwise, return False.
Example:print(all([1,2,3]))
Output
print(all([1,2,0,3]))
print(all([]))True
False
True -
- Return True if any element of the iterable is true. If the iterable is empty, return False.
Example:print(any([1,2,3,0]))
Output:
print(any([]))True
False -
- Returns a readable version of an object. Replaces none-ascii characters with escape character.
Example:str1 = ascii("I'm Govardhan")
Output:
str2 = ascii("I'm GovÄrdhan")
print(str1)
print(str2)"I'm Govardhan"
"I'm Gov\xe5rdhan" -
- Returns a binary version of a given number.
Example:binary = bin(9)
Output:
print(binary)0b1001
-
- Returns the boolean value of given object.
Example:print(bool(1))
Output:
print(bool(0))
print(bool(-1))
print(bool(''))
print(bool('A'))
print(bool(None))True
False
True
False
True
False -
- Returns True if specified object is callabel, otherwise it returns False.
Example:def fun():
Output:
n = 9
print(callabel(fun))True
-
- Returns the character that represents the specified Unicode.
Example:print(chr(71))
Output:G
-
- Returns a complex number by specifying a real number and an imaginary number.
Example:print(complex(9, 7))
Output:(9+7j)
-
- Used to create a dictionary.
Example:details = dict(name = "Govardhan", age = 33, country = "India")
Output:
print(details){'name': 'Govardhan', 'age': 33, 'country': 'India'}
-
- returns a tuple containing the quotient and the remainder when argument1 (divident) is divided by argument2 (divisor).
Example:qr = divmod(5, 3)
Output:
print(qr)(1, 2)
-
- Takes a collection and returns it as an enumerate object. Default start value is 0(zero).
Example:x = ['C', 'Java', 'Python']
Output:
y = enumerate(x,11)
print(list(y))[(11, 'C'), (12, 'Java'), (13, 'Python')]
-
- Which is to evaluates the specified expression, if the expression is legal python statement.
Note: expression must be in string format.
Example:print(eval('10+5'))
Output:15
-
- Converts a specified value into a floating point number.
Example:f1 = float(3)
Output:
f2 = float('3.14')
print(f1)
print(f2)3.0
3.14 -
- Converts the specified number into a hexadecimal value.
Example:hexanumber = hex(255)
Output:
print(hexanumber)0xff
-
- Returns a unique id for the specified object, which is nothing but object's memory address and will be different for each time you run the program.
Example:x = 5
Output:
y = 'Hello'
print(id(x))
print(id(y))9079136
47472264951600 -
- Converts the specified value into an integer number.
Example:
n1 = int(3.5)
Output:
n2 = int('12')
print(n1)
print(n2)3
12 -
- Returns True if the specified object is of the specified type, otherwise False.
Example:b1 = isinstance("Hello", (str, int, float))
Output:
b2 = isinstance("Hello", (int,float))
print(b1)
print(b2)True
False -
- Returns number of items in an object.
Example:lang = "python"
Output:
print(len(lang))6
-
- Returns a symbol table which contains necessary information about current program as a dictionary.
Example:print(locals())
Output:{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__':
, '__spec__': None, '__annotations__': {}, '__builtins__': } -
- executes a specified function for each item in a iterable.
Example:def languages(lang):
Output:
return len(lang)
lang = map(languages, ('C', 'Java', 'Python'))
print(lang)
print(list(lang))<map object at 0x2b98d1c74eb8>
[1, 4, 6] -
- Returns item with the highest value.
Example:lang = max('C','Java','Python')
Output:
print(lang)Python
-
- Returns item with the highest value.
Example:lang = max('C','Java','Python')
Output:
print(lang)C
-
- Converts an integer into octal string.
Example:octStr = oct(19)
Output:
print(octStr)0o23
-
- Returns the unicode code of a specified character.
Example:unicode = ord("A")
Output:
print(unicode)65
-
- Returns a reversed iterator object.
Example:lang = "Python"
Output:
rev = reversed(lang)
for ch in rev:
print(ch,end="")nohtyP