Functions Built-in Flashcards
mylist = [True, True, True]
x = all(mylist)
print(x)
True
mylist = [False, True, False]
x = any(mylist)
print(x)
True
x = ascii(“My name is Ståle”)
print(x)
‘My name is St\e5le’
x = bin(3)
print(x)
# The result will always have the prefix 0b 0b11
x = bool(1)
print(x)
True
x = bytearray(2)
print(x)
bytearray(b’\x00\x00’)
x = bytes(2)
print(x)
b’\x00\x00’
def x(): a = 5
print(callable(x))
True
x = chr(97)
print(x)
a
x = complex(3,5)
print(x)
(3+5j)
class Person: name = "John" age = 36 country = "Norway"
delattr(Person, ‘age’)
The age attribute will be deleted from the Person class
x = dict(name = “John”, age = 36, country = “Norway”)
print(x)
{‘name’: ‘John’, ‘age’: 36, ‘country’: ‘Norway’}
x = divmod(5, 2)
print(x)
(2, 1)
x = ('apple', 'banana', 'cherry') y = enumerate(x)
print(list(y))
[(0, ‘apple’), (1, ‘banana’), (2, ‘cherry’)]
ages = [12, 17, 18, 24]
adults = filter(lambda a: a>=18, ages)
for x in adults:
print(x)
18
24