Pro Python Deck Flashcards

1
Q

What is a variable in Python? Provide an example.

A

A variable in Python is a reserved memory location to store values. For example, x = 5 assigns the integer value 5 to variable x.

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

How do you create a list in Python with mixed data types? Provide an example.

A

A list in Python can include mixed data types and is defined with square brackets. Example: my_list = [1, 'Hello', 3.14]

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

Explain the use of the if statement in Python with an example.

A

The if statement is used for conditional execution. For example: if x > 0: print('Positive') will print ‘Positive’ if x is greater than 0.

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

How can you handle exceptions in Python? Provide a code snippet.

A

Exceptions in Python can be handled using the try-except block. Example:
```python
try:
print(10/0)
except ZeroDivisionError:
print(‘Cannot divide by zero’)
~~~

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

What is a function in Python? Provide an example of a simple function.

A

A function in Python is a block of code which only runs when it is called. For example, def greet(): print('Hello!') defines a function that prints ‘Hello!’.

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

How do you iterate over a list in Python? Provide an example using a for loop.

A

To iterate over a list in Python, you can use a for loop. Example:
```python
for item in [1, 2, 3]:
print(item)
~~~

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

Describe how to import a module in Python and provide an example with the math module.

A

To import a module in Python, use the import statement. For example, import math allows access to mathematical functions.

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

How do you create a class in Python? Provide an example with a simple class.

A

A class in Python is created using the class keyword. Example:
```python
class Dog:
def bark(self):
print(‘Woof!’)
~~~

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

Explain dictionary comprehension in Python with an example.

A

Dictionary comprehension provides a concise way to create dictionaries. Example: {x: x**2 for x in (1, 2, 3)} creates a dictionary with numbers as keys and their squares as values.

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

What is the use of the append() method in lists? Provide an example.

A

The append() method adds an element to the end of a list. Example: my_list = [1, 2]; my_list.append(3) results in [1, 2, 3].

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

What does the built-in function abs do in Python?

A

The built-in function abs is used for various purposes, for example…

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

What does the built-in function all do in Python?

A

The built-in function all is used for various purposes, for example…

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

What does the built-in function any do in Python?

A

The built-in function any is used for various purposes, for example…

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

What does the built-in function ascii do in Python?

A

The built-in function ascii is used for various purposes, for example…

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

What does the built-in function bin do in Python?

A

The built-in function bin is used for various purposes, for example…

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

What does the built-in function bool do in Python?

A

The built-in function bool is used for various purposes, for example…

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

What does the built-in function bytearray do in Python?

A

The built-in function bytearray is used for various purposes, for example…

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

What does the built-in function bytes do in Python?

A

The built-in function bytes is used for various purposes, for example…

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

How to implement recursion in Python?

A

Here’s a basic example of how recursion can be implemented: …

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

How to implement inheritance in Python?

A

Here’s a basic example of how inheritance can be implemented: …

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

How to implement polymorphism in Python?

A

Here’s a basic example of how polymorphism can be implemented: …

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

How to implement encapsulation in Python?

A

Here’s a basic example of how encapsulation can be implemented: …

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

How to implement iteration in Python?

A

Here’s a basic example of how iteration can be implemented: …

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

How to implement enumeration in Python?

A

Here’s a basic example of how enumeration can be implemented: …

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

How to implement serialization in Python?

A

Here’s a basic example of how serialization can be implemented: …

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

How to implement deserialization in Python?

A

Here’s a basic example of how deserialization can be implemented: …

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

Describe how pip is used in Python.

A

pip is a tool in Python that allows you to…

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

Describe how PyPI is used in Python.

A

PyPI is a tool in Python that allows you to…

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

Describe how virtualenv is used in Python.

A

virtualenv is a tool in Python that allows you to…

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

Describe how Jupyter Notebook is used in Python.

A

Jupyter Notebook is a tool in Python that allows you to…

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

Describe how pytest is used in Python.

A

pytest is a tool in Python that allows you to…

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

Describe how Flask is used in Python.

A

Flask is a tool in Python that allows you to…

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

Describe how Django is used in Python.

A

Django is a tool in Python that allows you to…

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

Explain int data type in Python. Provide an example.

A

int is a data type in Python that… Example: …

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

Explain float data type in Python. Provide an example.

A

float is a data type in Python that… Example: …

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

Explain complex data type in Python. Provide an example.

A

complex is a data type in Python that… Example: …

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

Explain str data type in Python. Provide an example.

A

str is a data type in Python that… Example: …

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

Explain list data type in Python. Provide an example.

A

list is a data type in Python that… Example: …

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

Explain tuple data type in Python. Provide an example.

A

tuple is a data type in Python that… Example: …

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

Explain dict data type in Python. Provide an example.

A

dict is a data type in Python that… Example: …

41
Q

Explain set data type in Python. Provide an example.

A

set is a data type in Python that… Example: …

42
Q

Provide an example of adding operation in Python.

A

This example shows how to perform adding: …

43
Q

Provide an example of subtracting operation in Python.

A

This example shows how to perform subtracting: …

44
Q

Provide an example of multiplying operation in Python.

A

This example shows how to perform multiplying: …

45
Q

Provide an example of dividing operation in Python.

A

This example shows how to perform dividing: …

46
Q

Discuss the use of math module in Python.

A

The math module is typically used for… Example: …

47
Q

Discuss the use of os module in Python.

A

The os module is typically used for… Example: …

48
Q

Discuss the use of sys module in Python.

A

The sys module is typically used for… Example: …

49
Q

Discuss the use of re module in Python.

A

The re module is typically used for… Example: …

50
Q

Discuss the use of json module in Python.

A

The json module is typically used for… Example: …

51
Q

Discuss the use of datetime module in Python.

A

The datetime module is typically used for… Example: …

52
Q

What is the difference between append and extend in Python?

A

Here’s how append differs from extend: …

53
Q

What is the difference between update and merge in Python?

A

Here’s how update differs from merge: …

54
Q

How does return work in Python? Provide an example.

A

The return statement is used in Python to… Example: …

55
Q

How does yield work in Python? Provide an example.

A

The yield statement is used in Python to… Example: …

56
Q

How does break work in Python? Provide an example.

A

The break statement is used in Python to… Example: …

57
Q

How does continue work in Python? Provide an example.

A

The continue statement is used in Python to… Example: …

58
Q

What are decorators in Python? Provide an example.

A

Decorators are functions that modify the functionality of another function. Example: @decorator_func def function(): pass

59
Q

How do you handle exceptions in Python? Give an example.

A

Exceptions in Python are handled using try-except blocks. Example: try: x = 1 / 0 except ZeroDivisionError: print('Error')

60
Q

Explain the use of the with statement in Python file handling.

A

The with statement simplifies exception handling by encapsulating common preparation and cleanup tasks in file handling.

61
Q

Explain the use of break in Python loops.

A

The break statement is commonly used in loops to… Example: …

62
Q

Explain the use of continue in Python loops.

A

The continue statement is commonly used in loops to… Example: …

63
Q

Explain the use of pass in Python loops.

A

The pass statement is commonly used in loops to… Example: …

64
Q

Describe the use of the print function in Python.

A

The print function is used to… Example: …

65
Q

Describe the use of the input function in Python.

A

The input function is used to… Example: …

66
Q

Describe the use of the len function in Python.

A

The len function is used to… Example: …

67
Q

Describe the use of the max function in Python.

A

The max function is used to… Example: …

68
Q

Describe the use of the min function in Python.

A

The min function is used to… Example: …

69
Q

Describe the use of the sorted function in Python.

A

The sorted function is used to… Example: …

70
Q

What is list comprehension in Python? Give an example.

A

list comprehension in Python is… Example: …

71
Q

What is dictionary comprehension in Python? Give an example.

A

dictionary comprehension in Python is… Example: …

72
Q

What is tuple unpacking in Python? Give an example.

A

tuple unpacking in Python is… Example: …

73
Q

What is lambda function in Python? Give an example.

A

lambda function in Python is… Example: …

74
Q

How do you use the os module in Python? Give an example.

A

The os module is used for… Example: …

75
Q

How do you use the sys module in Python? Give an example.

A

The sys module is used for… Example: …

76
Q

How do you use the datetime module in Python? Give an example.

A

The datetime module is used for… Example: …

77
Q

How do you use the json module in Python? Give an example.

A

The json module is used for… Example: …

78
Q

How do you use the re module in Python? Give an example.

A

The re module is used for… Example: …

79
Q

What are the benefits of using numpy package in Python?

A

The numpy package provides…

80
Q

What are the benefits of using pandas package in Python?

A

The pandas package provides…

81
Q

What are the benefits of using matplotlib package in Python?

A

The matplotlib package provides…

82
Q

What are the benefits of using seaborn package in Python?

A

The seaborn package provides…

83
Q

What are the benefits of using scikit-learn package in Python?

A

The scikit-learn package provides…

84
Q

How does append method work with lists in Python? Provide an example.

A

The append method is used with lists to… Example: …

85
Q

How does extend method work with lists in Python? Provide an example.

A

The extend method is used with lists to… Example: …

86
Q

How does insert method work with lists in Python? Provide an example.

A

The insert method is used with lists to… Example: …

87
Q

How does remove method work with lists in Python? Provide an example.

A

The remove method is used with lists to… Example: …

88
Q

How does pop method work with lists in Python? Provide an example.

A

The pop method is used with lists to… Example: …

89
Q

Explain the difference between class and instance in Python.

A

The difference between class and instance in Python is…

90
Q

Explain the difference between method and function in Python.

A

The difference between method and function in Python is…

91
Q

Explain the difference between mutable and immutable in Python.

A

The difference between mutable and immutable in Python is…

92
Q

Provide a use case for strings in Python.

A

A use case for strings in Python is…

93
Q

Provide a use case for lists in Python.

A

A use case for lists in Python is…

94
Q

Provide a use case for dictionaries in Python.

A

A use case for dictionaries in Python is…

95
Q

Provide a use case for sets in Python.

A

A use case for sets in Python is…

96
Q

Provide a use case for tuples in Python.

A

A use case for tuples in Python is…

97
Q

What is recursion in Python? Provide an example.

A

Recursion in Python is a process in which a function calls itself as a subroutine. Example: def recurse(x): if x <= 1: return x; else: return x * recurse(x - 1) calculates factorial.

98
Q

Describe how to create a virtual environment in Python.

A

To create a virtual environment in Python, use the venv module: python -m venv myenv creates a new virtual environment named myenv.