Software Engineering - Python Flashcards
What is Python?
Python is a
high-level
interpreted
general-purpose programming language
known for its
simplicity
readability
versatility
What are the key features of Python?
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
What are the main differences between Python 2 and Python 3?
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.
What are the basic data types in Python?
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)
What is the difference between a list and a tuple in Python?
Lists are mutable (can be modified)
and defined with square brackets [],
while tuples are immutable (cannot be modified)
and defined with parentheses ().
What is a dictionary in Python?
A dictionary is an unordered collection of key-value pairs,
defined with curly braces {}
and accessed by keys.
What are the main control flow statements in Python?
if/elif/else for conditional execution
for and while loops for iteration
break, continue, and pass for loop control
What is a function in Python?
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 ().
What are the differences between positional and keyword arguments in Python functions?
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
What is a lambda function in Python?
A lambda function is a
small, anonymous function defined with the lambda keyword,
often used for short, one-line operations.
What is a module in Python?
A module is a
file containing Python definitions and statements,
which can be imported into other Python files
or the interactive interpreter.
What is a package in Python?
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.
What is object-oriented programming (OOP) in Python?
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.
What is the difference between a class and an instance in Python?
A class is a blueprint or template for creating objects, while an instance is a specific object created from a class.
What is inheritance in Python?
Inheritance is a mechanism that allows a new class to be based on an existing class, inheriting its attributes and methods.
What is polymorphism in Python?
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).
What are decorators in Python?
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.
What is exception handling in Python?
Exception handling is a mechanism for dealing with runtime errors or unexpected conditions, using try/except/finally blocks.
What are some common built-in exceptions in Python?
TypeError, ValueError, NameError, IndexError, KeyError, and ImportError.
What are some popular Python libraries and frameworks for web development?
Django, Flask, FastAPI, Pyramid, and Tornado.
What are some popular Python libraries for data analysis and machine learning?
NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, and PyTorch.
What is pip in Python?
pip is the standard package manager for Python, used to install and manage third-party libraries and packages.
What are virtual environments in Python?
Virtual environments are isolated Python environments that allow you to install packages and dependencies specific to a project, without affecting the global Python installation.
What are some best practices for writing clean and maintainable Python code?
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).
What are some tools for testing and debugging Python code?
pytest for unit testing, pdb for interactive debugging, and IDEs like PyCharm, VSCode, or Jupyter Notebook for integrated debugging and testing features.