Pro Python Deck Flashcards

(98 cards)

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
How to implement `serialization` in Python?
Here's a basic example of how `serialization` can be implemented: ...
26
How to implement `deserialization` in Python?
Here's a basic example of how `deserialization` can be implemented: ...
27
Describe how `pip` is used in Python.
`pip` is a tool in Python that allows you to...
28
Describe how `PyPI` is used in Python.
`PyPI` is a tool in Python that allows you to...
29
Describe how `virtualenv` is used in Python.
`virtualenv` is a tool in Python that allows you to...
30
Describe how `Jupyter Notebook` is used in Python.
`Jupyter Notebook` is a tool in Python that allows you to...
31
Describe how `pytest` is used in Python.
`pytest` is a tool in Python that allows you to...
32
Describe how `Flask` is used in Python.
`Flask` is a tool in Python that allows you to...
33
Describe how `Django` is used in Python.
`Django` is a tool in Python that allows you to...
34
Explain `int` data type in Python. Provide an example.
`int` is a data type in Python that... Example: ...
35
Explain `float` data type in Python. Provide an example.
`float` is a data type in Python that... Example: ...
36
Explain `complex` data type in Python. Provide an example.
`complex` is a data type in Python that... Example: ...
37
Explain `str` data type in Python. Provide an example.
`str` is a data type in Python that... Example: ...
38
Explain `list` data type in Python. Provide an example.
`list` is a data type in Python that... Example: ...
39
Explain `tuple` data type in Python. Provide an example.
`tuple` is a data type in Python that... Example: ...
40
Explain `dict` data type in Python. Provide an example.
`dict` is a data type in Python that... Example: ...
41
Explain `set` data type in Python. Provide an example.
`set` is a data type in Python that... Example: ...
42
Provide an example of `adding` operation in Python.
This example shows how to perform `adding`: ...
43
Provide an example of `subtracting` operation in Python.
This example shows how to perform `subtracting`: ...
44
Provide an example of `multiplying` operation in Python.
This example shows how to perform `multiplying`: ...
45
Provide an example of `dividing` operation in Python.
This example shows how to perform `dividing`: ...
46
Discuss the use of `math` module in Python.
The `math` module is typically used for... Example: ...
47
Discuss the use of `os` module in Python.
The `os` module is typically used for... Example: ...
48
Discuss the use of `sys` module in Python.
The `sys` module is typically used for... Example: ...
49
Discuss the use of `re` module in Python.
The `re` module is typically used for... Example: ...
50
Discuss the use of `json` module in Python.
The `json` module is typically used for... Example: ...
51
Discuss the use of `datetime` module in Python.
The `datetime` module is typically used for... Example: ...
52
What is the difference between `append` and `extend` in Python?
Here's how `append` differs from `extend`: ...
53
What is the difference between `update` and `merge` in Python?
Here's how `update` differs from `merge`: ...
54
How does `return` work in Python? Provide an example.
The `return` statement is used in Python to... Example: ...
55
How does `yield` work in Python? Provide an example.
The `yield` statement is used in Python to... Example: ...
56
How does `break` work in Python? Provide an example.
The `break` statement is used in Python to... Example: ...
57
How does `continue` work in Python? Provide an example.
The `continue` statement is used in Python to... Example: ...
58
What are decorators in Python? Provide an example.
Decorators are functions that modify the functionality of another function. Example: `@decorator_func def function(): pass`
59
How do you handle exceptions in Python? Give an example.
Exceptions in Python are handled using try-except blocks. Example: `try: x = 1 / 0 except ZeroDivisionError: print('Error')`
60
Explain the use of the `with` statement in Python file handling.
The `with` statement simplifies exception handling by encapsulating common preparation and cleanup tasks in file handling.
61
Explain the use of `break` in Python loops.
The `break` statement is commonly used in loops to... Example: ...
62
Explain the use of `continue` in Python loops.
The `continue` statement is commonly used in loops to... Example: ...
63
Explain the use of `pass` in Python loops.
The `pass` statement is commonly used in loops to... Example: ...
64
Describe the use of the `print` function in Python.
The `print` function is used to... Example: ...
65
Describe the use of the `input` function in Python.
The `input` function is used to... Example: ...
66
Describe the use of the `len` function in Python.
The `len` function is used to... Example: ...
67
Describe the use of the `max` function in Python.
The `max` function is used to... Example: ...
68
Describe the use of the `min` function in Python.
The `min` function is used to... Example: ...
69
Describe the use of the `sorted` function in Python.
The `sorted` function is used to... Example: ...
70
What is `list comprehension` in Python? Give an example.
`list comprehension` in Python is... Example: ...
71
What is `dictionary comprehension` in Python? Give an example.
`dictionary comprehension` in Python is... Example: ...
72
What is `tuple unpacking` in Python? Give an example.
`tuple unpacking` in Python is... Example: ...
73
What is `lambda function` in Python? Give an example.
`lambda function` in Python is... Example: ...
74
How do you use the `os` module in Python? Give an example.
The `os` module is used for... Example: ...
75
How do you use the `sys` module in Python? Give an example.
The `sys` module is used for... Example: ...
76
How do you use the `datetime` module in Python? Give an example.
The `datetime` module is used for... Example: ...
77
How do you use the `json` module in Python? Give an example.
The `json` module is used for... Example: ...
78
How do you use the `re` module in Python? Give an example.
The `re` module is used for... Example: ...
79
What are the benefits of using `numpy` package in Python?
The `numpy` package provides...
80
What are the benefits of using `pandas` package in Python?
The `pandas` package provides...
81
What are the benefits of using `matplotlib` package in Python?
The `matplotlib` package provides...
82
What are the benefits of using `seaborn` package in Python?
The `seaborn` package provides...
83
What are the benefits of using `scikit-learn` package in Python?
The `scikit-learn` package provides...
84
How does `append` method work with lists in Python? Provide an example.
The `append` method is used with lists to... Example: ...
85
How does `extend` method work with lists in Python? Provide an example.
The `extend` method is used with lists to... Example: ...
86
How does `insert` method work with lists in Python? Provide an example.
The `insert` method is used with lists to... Example: ...
87
How does `remove` method work with lists in Python? Provide an example.
The `remove` method is used with lists to... Example: ...
88
How does `pop` method work with lists in Python? Provide an example.
The `pop` method is used with lists to... Example: ...
89
Explain the difference between `class` and `instance` in Python.
The difference between `class` and `instance` in Python is...
90
Explain the difference between `method` and `function` in Python.
The difference between `method` and `function` in Python is...
91
Explain the difference between `mutable` and `immutable` in Python.
The difference between `mutable` and `immutable` in Python is...
92
Provide a use case for `strings` in Python.
A use case for `strings` in Python is...
93
Provide a use case for `lists` in Python.
A use case for `lists` in Python is...
94
Provide a use case for `dictionaries` in Python.
A use case for `dictionaries` in Python is...
95
Provide a use case for `sets` in Python.
A use case for `sets` in Python is...
96
Provide a use case for `tuples` in Python.
A use case for `tuples` in Python is...
97
What is recursion in Python? Provide an example.
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
Describe how to create a virtual environment in Python.
To create a virtual environment in Python, use the `venv` module: `python -m venv myenv` creates a new virtual environment named `myenv`.