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
Q

What is a set in Python?

A

An unordered collection of unique elements.

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

What does the ‘return’ statement do in a function?

A

It exits the function and optionally returns a value.

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

Fill in the blank: The ______ method is used to add items to a list.

28
Q

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

A

To simplify exception handling by encapsulating common preparation and cleanup tasks.

29
Q

True or False: String concatenation in Python can be done using the ‘+’ operator.

30
Q

What is the ‘map()’ function used for?

A

To apply a function to all items in an iterable.

31
Q

What does the ‘filter()’ function do?

A

It constructs an iterator from elements of an iterable for which a function returns true.

32
Q

What is a lambda function in Python?

A

An anonymous function expressed as a single statement.

33
Q

Fill in the blank: In Python, ______ can be used to create a generator.

34
Q

What is the purpose of the ‘global’ keyword?

A

To declare a variable as global, allowing it to be modified inside a function.

35
Q

What is a decorator in Python?

A

A function that modifies another function.

36
Q

True or False: List indexing in Python starts at 1.

37
Q

What is exception handling?

A

The process of responding to the occurrence of exceptions.

38
Q

What does the ‘finally’ block do in exception handling?

A

It executes code after the try and except blocks, regardless of whether an exception occurred.

39
Q

What is a Python package?

A

A way of organizing related modules in a directory hierarchy.

40
Q

What does the ‘os’ module provide?

A

Functions for interacting with the operating system.

41
Q

What is ‘enumerate()’ used for?

A

To add a counter to an iterable and return it as an enumerate object.

42
Q

Fill in the blank: The ______ operator checks for equality between two values.

43
Q

What is the purpose of the ‘assert’ statement?

A

To test if a condition is true, and if not, raise an AssertionError.

44
Q

What does the ‘type()’ function return?

A

The type of an object.

45
Q

True or False: Python uses indentation to define code blocks.

46
Q

What is the ‘json’ module used for?

A

To work with JSON data in Python.

47
Q

What is the purpose of the ‘input()’ function?

A

To take input from the user.

48
Q

What does the ‘strip()’ method do for strings?

A

It removes leading and trailing whitespace.

49
Q

What is the output of the expression ‘not True’?

50
Q

What is the purpose of the ‘else’ statement in loops?

A

To specify a block of code to run when the loop completes normally.

51
Q

What is a virtual environment in Python?

A

A self-contained directory that contains a Python installation for a particular version of Python.

52
Q

What does ‘pip’ stand for?

A

Pip Installs Packages.

53
Q

What is the ‘__init__’ method in Python?

A

The constructor method that initializes a newly created object.

54
Q

What is the purpose of the ‘super()’ function?

A

To call a method from the parent class.

55
Q

What is the difference between ‘==’ and ‘is’?

A

’==’ checks for value equality, while ‘is’ checks for reference equality.

56
Q

What does ‘slice’ mean in Python?

A

To obtain a subset of a sequence by specifying a start and end index.

57
Q

Fill in the blank: A ______ is a sequence of characters in Python.

58
Q

What is the ‘re’ module used for?

A

To work with regular expressions.

59
Q

What does the ‘sorted()’ function do?

A

It returns a sorted list of the specified iterable’s elements.

60
Q

True or False: Python allows you to create nested functions.

61
Q

What is the purpose of the ‘break’ statement in a loop?

A

To exit the loop immediately.

62
Q

What is the significance of ‘None’ in Python?

A

It represents the absence of a value or a null value.

63
Q

What does the ‘join()’ method do for strings?

A

It concatenates the elements of an iterable into a single string.

64
Q

What is the result of ‘5 // 2’ in Python?

65
Q

What is a ‘list slice’?

A

A portion of a list defined by a start and end index.

66
Q

What does the ‘any()’ function do?

A

It returns True if any element of the iterable is true.

67
Q

What is the purpose of the ‘continue’ statement?

A

To skip the current iteration and continue with the next one.