Python Basics Flashcards

Python Vocabulary

1
Q

What is a variable in Python?

A

A variable is a reserved memory location to store values.

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

What symbol is used for comments in Python?

A

#

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

Fill in the blank: In Python, a list is defined using ______.

A

square brackets []

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

What function is used to output data to the console in Python?

A

print()

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

What is a function in Python?

A

A block of reusable code that performs a specific task.

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

What keyword is used to define a function in Python?

A

def

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

True or False: Python supports multiple inheritance.

A

True

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

What is a dictionary in Python?

A

A collection of key-value pairs.

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

What does the ‘len()’ function do?

A

It returns the number of items in an object.

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

What is the purpose of the ‘if’ statement in Python?

A

To execute a block of code conditionally.

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

Fill in the blank: In Python, the ______ keyword is used to handle exceptions.

A

try

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

What is a module in Python?

A

A file containing Python definitions and statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
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
16
Q

What are tuples in Python?

A

Immutable sequences of values.

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

What does the ‘import’ statement do?

A

It allows you to include external modules in your code.

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

What is a class in Python?

A

A blueprint for creating objects that encapsulate data and behavior.

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

What is the purpose of the ‘self’ keyword in a class?

A

It refers to the instance of the class.

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

Fill in the blank: A ______ is a function defined inside a class.

A

method

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

What is a list comprehension in Python?

A

A concise way to create lists using a single line of code.

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

True or False: The ‘pass’ statement in Python does nothing.

A

True

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

What is the output of ‘2 + 3 * 4’ in Python?

A

14

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

What does the ‘break’ statement do in a loop?

A

It exits the loop prematurely.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is a set in Python?
An unordered collection of unique elements.
26
What does the 'return' statement do in a function?
It exits the function and optionally returns a value.
27
Fill in the blank: The ______ method is used to add items to a list.
append()
28
What is the purpose of the 'with' statement in Python?
To simplify exception handling by encapsulating common preparation and cleanup tasks.
29
True or False: String concatenation in Python can be done using the '+' operator.
True
30
What is the 'map()' function used for?
To apply a function to all items in an iterable.
31
What does the 'filter()' function do?
It constructs an iterator from elements of an iterable for which a function returns true.
32
What is a lambda function in Python?
An anonymous function expressed as a single statement.
33
Fill in the blank: In Python, ______ can be used to create a generator.
yield
34
What is the purpose of the 'global' keyword?
To declare a variable as global, allowing it to be modified inside a function.
35
What is a decorator in Python?
A function that modifies another function.
36
True or False: List indexing in Python starts at 1.
False
37
What is exception handling?
The process of responding to the occurrence of exceptions.
38
What does the 'finally' block do in exception handling?
It executes code after the try and except blocks, regardless of whether an exception occurred.
39
What is a Python package?
A way of organizing related modules in a directory hierarchy.
40
What does the 'os' module provide?
Functions for interacting with the operating system.
41
What is 'enumerate()' used for?
To add a counter to an iterable and return it as an enumerate object.
42
Fill in the blank: The ______ operator checks for equality between two values.
==
43
What is the purpose of the 'assert' statement?
To test if a condition is true, and if not, raise an AssertionError.
44
What does the 'type()' function return?
The type of an object.
45
True or False: Python uses indentation to define code blocks.
True
46
What is the 'json' module used for?
To work with JSON data in Python.
47
What is the purpose of the 'input()' function?
To take input from the user.
48
What does the 'strip()' method do for strings?
It removes leading and trailing whitespace.
49
What is the output of the expression 'not True'?
False
50
What is the purpose of the 'else' statement in loops?
To specify a block of code to run when the loop completes normally.
51
What is a virtual environment in Python?
A self-contained directory that contains a Python installation for a particular version of Python.
52
What does 'pip' stand for?
Pip Installs Packages.
53
What is the '__init__' method in Python?
The constructor method that initializes a newly created object.
54
What is the purpose of the 'super()' function?
To call a method from the parent class.
55
What is the difference between '==' and 'is'?
'==' checks for value equality, while 'is' checks for reference equality.
56
What does 'slice' mean in Python?
To obtain a subset of a sequence by specifying a start and end index.
57
Fill in the blank: A ______ is a sequence of characters in Python.
string
58
What is the 're' module used for?
To work with regular expressions.
59
What does the 'sorted()' function do?
It returns a sorted list of the specified iterable's elements.
60
True or False: Python allows you to create nested functions.
True
61
What is the purpose of the 'break' statement in a loop?
To exit the loop immediately.
62
What is the significance of 'None' in Python?
It represents the absence of a value or a null value.
63
What does the 'join()' method do for strings?
It concatenates the elements of an iterable into a single string.
64
What is the result of '5 // 2' in Python?
2
65
What is a 'list slice'?
A portion of a list defined by a start and end index.
66
What does the 'any()' function do?
It returns True if any element of the iterable is true.
67
What is the purpose of the 'continue' statement?
To skip the current iteration and continue with the next one.