Software Engineering - Python Flashcards

1
Q

What is Python?

A

Python is a
high-level
interpreted
general-purpose programming language

known for its
simplicity
readability
versatility

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

What are the key features of Python?

A

Easy to learn and read,

dynamically typed

interpreted

multi-paradigm (supports object-oriented

procedural, and functional programming)

and has a large standard library

third-party ecosystem

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

What are the main differences between Python 2 and Python 3?

A

Python 3 introduced changes in
print syntax
integer division
Unicode support
and some renamed or removed functions.

Python 2 is no longer maintained as of January 2020.

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

What are the basic data types in Python?

A

Numeric types (int, float, complex)

sequences (list, tuple, range)

text type (str)

binary types (bytes, bytearray)

mapping type (dict)

set types (set, frozenset)

and boolean type (bool)

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

What is the difference between a list and a tuple in Python?

A

Lists are mutable (can be modified)
and defined with square brackets [],

while tuples are immutable (cannot be modified)
and defined with parentheses ().

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

What is a dictionary in Python?

A

A dictionary is an unordered collection of key-value pairs,

defined with curly braces {}

and accessed by keys.

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

What are the main control flow statements in Python?

A

if/elif/else for conditional execution

for and while loops for iteration

break, continue, and pass for loop control

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

What is a function in Python?

A

A function is a
reusable block of code that performs a specific task

defined with the def keyword

called by its name followed by

parentheses ().

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

What are the differences between positional and keyword arguments in Python functions?

A

Positional arguments
are passed by position and must be provided in the correct order

keyword arguments
are passed by name and can be provided in any order

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

What is a lambda function in Python?

A

A lambda function is a

small, anonymous function defined with the lambda keyword,

often used for short, one-line operations.

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

What is a module in Python?

A

A module is a
file containing Python definitions and statements,

which can be imported into other Python files

or the interactive interpreter.

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

What is a package in Python?

A

A package is a way of organizing related modules into a directory hierarchy, with a special init.py file to mark the directory as a package.

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

What is object-oriented programming (OOP) in Python?

A

OOP is a programming paradigm based on the concept of objects, which can contain data (attributes) and code (methods). Python supports OOP with classes and inheritance.

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

What is the difference between a class and an instance in Python?

A

A class is a blueprint or template for creating objects, while an instance is a specific object created from a class.

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

What is inheritance in Python?

A

Inheritance is a mechanism that allows a new class to be based on an existing class, inheriting its attributes and methods.

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

What is polymorphism in Python?

A

Polymorphism is the ability of objects to take on multiple forms, through method overriding (redefining inherited methods) or method overloading (defining methods with the same name but different parameters).

17
Q

What are decorators in Python?

A

Decorators are a way to modify or enhance the behavior of functions or classes without directly changing their source code, using the @decorator_name syntax.

18
Q

What is exception handling in Python?

A

Exception handling is a mechanism for dealing with runtime errors or unexpected conditions, using try/except/finally blocks.

19
Q

What are some common built-in exceptions in Python?

A

TypeError, ValueError, NameError, IndexError, KeyError, and ImportError.

20
Q

What are some popular Python libraries and frameworks for web development?

A

Django, Flask, FastAPI, Pyramid, and Tornado.

21
Q

What are some popular Python libraries for data analysis and machine learning?

A

NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, and PyTorch.

22
Q

What is pip in Python?

A

pip is the standard package manager for Python, used to install and manage third-party libraries and packages.

23
Q

What are virtual environments in Python?

A

Virtual environments are isolated Python environments that allow you to install packages and dependencies specific to a project, without affecting the global Python installation.

24
Q

What are some best practices for writing clean and maintainable Python code?

A

Follow PEP 8 style guide, use meaningful names for variables and functions, keep functions small and focused, use comments and docstrings to document code, and use version control (e.g., Git).

25
Q

What are some tools for testing and debugging Python code?

A

pytest for unit testing, pdb for interactive debugging, and IDEs like PyCharm, VSCode, or Jupyter Notebook for integrated debugging and testing features.