Built-in Functions Flashcards

1
Q

what does cmp() do?

A

cmp() is a n-built function in Python, it is used to compare two objects and returns value according to the given values. It does not return ‘true’ or ‘false’ instead of ‘true’ / ‘false’, it returns negative, zero or positive value based on the given input.

Syntax: cmp(obj1, obj2)

Here, cmp() will return negative (-1) if obj1obj2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the different outputs of cmp()?

A

Syntax: cmp(obj1, obj2)

Here, cmp() will return negative (-1) if obj1obj2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does bit_length() do?

A

Return the number of bits necessary to represent an integer in binary, excluding the sign and leading zeros

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what would bit_length(37) return?

A
>>> n = -37
>>> bin(n)
'-0b100101'
>>> n.bit_length()
6
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does enumerate() do?

A

enumerate(iterable, start=0)

Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object. This enumerate object can then be used directly in for loops or be converted into a list of tuples using list() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

why is enumerate() helpful?

A

because it allows you to grab indexes and/or have a counter while going through an iterable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the map() function do?

A

map(fun, iter)

map() function returns a map object(which is an iterator) of the results after applying the given function to each item of a given iterable (list, tuple etc.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When should you use the map() function?

A

Whenever you want to get an output of a function being run on an iterable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What date function gives you a date object formatted with yyyy-mm-dd?

A

datetime.date.today()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly