Python Flashcards

(71 cards)

1
Q

What is the syntax to output ‘Hello, World!’ in Python?

A

print(‘Hello, World!’)

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

True or False: Python is a statically typed language.

A

False

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

Fill in the blank: In Python, a variable can be declared by assigning a value using the ____ operator.

A

=

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

What data type is used to represent a sequence of characters in Python?

A

String

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

What is the keyword used to define a function in Python?

A

def

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

True or False: Lists in Python are immutable.

A

False

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

What is the output of the expression 3 * ‘Python’?

A

‘PythonPythonPython’

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

What symbol is used for comments in Python?

A

#

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

What is the default return value of a function in Python that does not return anything?

A

None

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

What data type would you use to store a collection of unique items in Python?

A

Set

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

What is the method to add an item to a list in Python?

A

.append()

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

What is the syntax for an if statement in Python?

A

if condition:

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

True or False: Tuples are mutable in Python.

A

False

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

What is the correct way to create a dictionary in Python?

A

{}

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

What does the len() function do in Python?

A

Returns the number of items in an object.

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

What keyword is used to create a class in Python?

A

class

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

What is the output of 5 // 2 in Python?

A

2

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

What is the syntax to import a module named ‘math’?

A

import math

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

Fill in the blank: In Python, the ____ statement is used to handle exceptions.

A

try

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

What is the result of the expression ‘5’ + ‘6’ in Python?

A

‘56’

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

True or False: The ‘break’ statement is used to exit a loop in Python.

A

True

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

What operator is used for exponentiation in Python?

A

**

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

What is the output of the expression [1, 2] + [3, 4]?

A

[1, 2, 3, 4]

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

What is the syntax for a while loop in Python?

A

while condition:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the purpose of the 'self' parameter in a class method?
To refer to the instance of the class.
26
What built-in function can be used to read a line from a file?
readline()
27
True or False: Python supports multiple inheritance.
True
28
What method is used to remove an item from a list by value?
.remove()
29
What keyword is used to define a generator function in Python?
yield
30
What is the output of the expression (1 == 1) and (2 == 2)?
True
31
What data type is used to represent true or false values in Python?
Boolean
32
What is a lambda function in Python?
An anonymous function defined with the lambda keyword.
33
Fill in the blank: A ____ is a collection of items that is ordered and changeable.
list
34
What is the syntax for a for loop in Python?
for item in iterable:
35
What method can be used to sort a list in Python?
.sort()
36
True or False: Python uses indentation to define the scope of loops and functions.
True
37
What does the 'continue' statement do in a loop?
Skips the current iteration and continues to the next one.
38
What is the result of the expression isinstance(5, int)?
True
39
What is the purpose of the 'with' statement in Python?
To simplify exception handling by encapsulating common preparation and cleanup tasks.
40
What method is used to convert a string to lowercase in Python?
.lower()
41
What does the 'map()' function do in Python?
Applies a function to all items in an iterable.
42
Fill in the blank: In Python, ____ is a way to define a function that can take any number of arguments.
*args
43
What is the purpose of the 'pass' statement in Python?
It is a null statement used as a placeholder.
44
What is the output of the expression 10 % 3?
1
45
What is the syntax to create a tuple in Python?
(item1, item2, ...)
46
True or False: Dictionaries in Python are ordered collections.
True (as of Python 3.7)
47
What is the syntax for defining a class method in Python?
def method_name(cls):
48
What data type is represented by the following: {'name': 'Alice', 'age': 25}?
Dictionary
49
What function is used to convert a string to an integer in Python?
int()
50
Fill in the blank: The ____ function returns the smallest of the input values.
min
51
What is the purpose of the 'return' statement in a function?
To exit the function and return a value.
52
What is the syntax for a list comprehension in Python?
[expression for item in iterable]
53
True or False: Python allows the use of both single and double quotes for strings.
True
54
What is the output of the expression 'abc'.upper()?
'ABC'
55
What is the keyword used to inherit from a class in Python?
(class ChildClass(ParentClass):)
56
What is the purpose of the 'import' statement?
To include external modules into the current script.
57
What does the 'filter()' function do in Python?
Filters items out of an iterable based on a function.
58
Fill in the blank: In Python, ____ is the keyword used to define a module.
import
59
What method is used to convert a list to a set?
set()
60
What is the output of the expression 'hello'.replace('e', 'a')?
'hallo'
61
What is the syntax for a nested if statement in Python?
if condition1: if condition2:
62
True or False: Python has built-in support for complex numbers.
True
63
What method is used to find the length of a dictionary?
len()
64
What is the output of the expression [x**2 for x in range(5)]?
[0, 1, 4, 9, 16]
65
What is the syntax to create an empty set in Python?
empty_set = set()
66
Fill in the blank: The ____ statement is used to define a block of code that will not execute unless a certain condition is met.
if
67
What is the method to convert a list to a string in Python?
''.join(list)
68
What is the output of the expression '123'.isdigit()?
True
69
What keyword is used to define a static method in a class?
@staticmethod
70
True or False: Python supports list slicing.
True
71
What is the syntax for handling exceptions in Python?
try: ... except ExceptionType: ...