Built-in Functions (1) Flashcards
#Built in functions #Write the arguments of slice()
slice(stop)
slice(start, stop, step)
Outcome of:
String =’GeeksforGeeks’
Gee
ek
s1 = slice(3)
s2 = slice(1, 5, 2)
print(String[s1])
print(String[s2])
#Built in functions #Write the arguments of .countOf()
Operator.countOf(freq = a, value = b)
Count frequency of 3
arr = [ 1, 2, 3, 3, 3 ]
from operator import *
arr = [ 1, 2, 3, 3, 3 ]
print(countOf(arr, 3))
#Built in functions #Write the arguments of copysign() and explain what it does
math.copysign(x, y)
Returns : float value consisting of magnitude from parameter x and the sign from parameter y.
Outcome of:
import math
math.copysign(-5,7)
5
#Built in functions # int.bit_length(), explain what it does
Returns the number of bits required to represent an integer in binary, excluding the sign and leading zeros.
Outcome of:
num = 7
print(num.bit_length())
3
#Built in functions #Write the arguments of isinstance() and explain what it does
isinstance(obj, class)
Returns : True, if object belongs to the given class/type if single class is passed or any of the class/type if tuple of class/type is passed, else returns False. Raises a TypeError if anything other than mentioned valid class type.
Check whether the object test=’stre’ belongs to the class integer
test=’stre’
isinstance(test, int)
Outcome:
False
Write the arguments of range()
range(start, stop, step)
Get this outcome using range():
[0, 2, 4, 6, 8]
list(range(0,10,2))
Write the arguments of set() and explain what it does
set(iterable)
Returns : An empty set if no element is passed. Non-repeating element iterable modified as passed as argument.
Code
lis1 = [ 3, 4, 1, 4, 5 ]
{1, 3, 4, 5}
set(lis1)
Parameters of hash(obj) and explain what it does
obj : The object which we need to convert into hash.
Returns : Returns the hashed value if possible.