3. Python Advanced Flashcards

1
Q

What does the built-in function “len()” do?

A

Returns the number of items in an object.

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

What does “type()” return?

A

The type of an object.

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

What does “range()” do?

A

Generates a sequence of numbers.

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

What does “input()” do?

A

Gets input from the user as a string.

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

What does “int()” do?

A

Converts a value to an integer.

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

What does “str()” do?

A

Converts a value to a string.

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

What does “float()” do?

A

Converts a value to a float.

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

What does “bool()” do?

A

Converts a value to a Boolean.

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

What does “sum()” do?

A

Returns the sum of all items in an iterable.

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

What does “sorted()” do?

A

Returns a sorted version of an iterable.

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

What does “enumerate()” do?

A

Adds a counter to an iterable.

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

What does “zip()” do?

A

Combines multiple iterables element-wise.

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

What does “str.lower()” do?

A

Returns the string in lowercase.

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

What does “str.strip()” do?

A

Removes leading and trailing whitespace.

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

What does “str.split()” do?

A

Splits a string into a list.

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

What does “str.join()” do?

A

Joins list elements into a string.

17
Q

What does “str.replace()” do?

A

Replaces parts of a string.

18
Q

What does “list.append()” do?

A

Adds an item to the end of the list.

19
Q

What does “list.pop()” do?

A

Removes and returns the last item.

20
Q

What does “dict.get()” do?

A

Returns the value for a key, or default if key is not found.

21
Q

What does “dict.items()” do?

A

Returns key-value pairs in a dictionary.

22
Q

What causes an IndentationError?

A

Incorrect or inconsistent indentation.

23
Q

What causes a SyntaxError?

A

Invalid Python code structure.

24
Q

What causes a NameError?

A

Using a variable that hasn’t been defined.

25
What causes a TypeError?
Applying an operation to an object of the wrong type.
26
What causes an IndexError?
Accessing an invalid list index.
27
What is the "math" module used for?
Advanced math functions.
28
What is the "random" module used for?
Random number generation.
29
What is the "datetime" module used for?
Working with dates and times.
30
What is the "os" module used for?
Interacting with the operating system.
31
What is the "json" module used for?
Working with JSON data.
32
What does a list comprehension look like?
Example: [x*2 for x in range(5)]
33
When should you use a set over a list?
When you need unique items and fast membership checks.
34
What does "with open(filename) as f:" do?
Opens a file and automatically closes it after use.