Functions Built-in Flashcards

(39 cards)

1
Q

mylist = [True, True, True]
x = all(mylist)
print(x)

A

True

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

mylist = [False, True, False]
x = any(mylist)
print(x)

A

True

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

x = ascii(“My name is Ståle”)

print(x)

A

‘My name is St\e5le’

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

x = bin(3)

print(x)

A
# The result will always have the prefix 0b
0b11
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

x = bool(1)

print(x)

A

True

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

x = bytearray(2)

print(x)

A

bytearray(b’\x00\x00’)

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

x = bytes(2)

print(x)

A

b’\x00\x00’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
def x():
  a = 5

print(callable(x))

A

True

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

x = chr(97)

print(x)

A

a

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

x = complex(3,5)

print(x)

A

(3+5j)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
class Person:
  name = "John"
  age = 36
  country = "Norway"

delattr(Person, ‘age’)

A

The age attribute will be deleted from the Person class

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

x = dict(name = “John”, age = 36, country = “Norway”)

print(x)

A

{‘name’: ‘John’, ‘age’: 36, ‘country’: ‘Norway’}

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

x = divmod(5, 2)

print(x)

A

(2, 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
x = ('apple', 'banana', 'cherry')
y = enumerate(x)

print(list(y))

A

[(0, ‘apple’), (1, ‘banana’), (2, ‘cherry’)]

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

ages = [12, 17, 18, 24]

adults = filter(lambda a: a>=18, ages)
for x in adults:
print(x)

A

18

24

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

x = float(3)

print(x)

17
Q

x = format(0.5, ‘%’)

print(x)

18
Q

mylist = [‘apple’, ‘banana’, ‘cherry’]
x = frozenset(mylist)
print(x)

A

frozenset({‘apple’, ‘banana’, ‘cherry’})

19
Q
class Person:
  name = "John"
  age = 36
  country = "Norway"

x = getattr(Person, ‘age’)

print(x)

20
Q
class Person:
  name = "John"
  age = 36
  country = "Norway"

x = hasattr(Person, ‘age’)

print(x)

21
Q

x = hex(255)

print(x)

A
#'0x' prefixes everything
0xff
22
Q

What is id()?

A

Returns a memory address. It will be different every time.

23
Q

print(“Enter your name:”)

x = input()

A

Allows the user to input stuff

24
Q

x = isinstance(5, int)

print(x)

25
``` class myAge: age = 36 ``` ``` class myObj(myAge): name = "John" age = myAge ``` x = issubclass(myObj, myAge) print(x)
True
26
x = iter(["apple", "banana", "cherry"]) print(next(x)) print(next(x)) print(next(x))
apple banana cherry
27
x = map(lambda a: len(a), ('apple', 'banana', 'cherry')) | print(list(x))
[5, 6, 6]
28
x = oct(200) print(x)
``` #Always starts with '0o' 0o310 ```
29
f = open("demofile.txt", "r") print(f.read())
Hello! Welcome to demofile.txt This file is for testing purposes. Good Luck!
30
x = ord("h") print(x)
``` #converts to unicode. opposite of ascii(). 104 ```
31
x = pow(4, 3) print(x)
64
32
alph = ["a", "b", "c", "d"] ralph = reversed(alph) for x in ralph: print(x)
d c b a
33
``` class Person: name = "John" age = 36 country = "Norway" ``` setattr(Person, 'age', 40) The age property will now have the value: 40 x = getattr(Person, 'age') print(x)
40
34
a = ("a", "b", "c", "d", "e", "f", "g", "h") x = slice(2) print(a[x])
('a', 'b')
35
a = ("b", "g", "a", "d", "f", "c", "h", "e") x = sorted(a) print(x)
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
36
x = tuple(("apple", "banana", "cherry")) print(x)
('banana', 'cherry', 'apple')
37
``` a = ["John", "Charles", "Mike"] b = ["Jenny", "Christy", "Monica"] ``` x = zip(a, b) print(list(x))
[('John', 'Jenny'), ('Charles', 'Christy'), ('Mike', 'Monica')]
38
``` def hacker_speak(txt): return txt.translate(str.maketrans('aeis', '4315')) ``` print(hacker_speak('games for life!'))
g4m35 f0r l1f3!
39
print(eval('3*2'))
6