1. What is Python and what makes it popular among programmers?
Ans:
Python is a versatile, high-level programming language celebrated for its simplicity and readability. It supports multiple programming approaches, including object-oriented and functional styles. Its clear syntax, extensive standard library, platform independence and active community make it a favorite for web development, automation, data science and many other fields.
2. What is PEP 8 and why should you follow it?
Ans:
The approved style guide for PEP 8 is writing Python code. It provides a consistent set of rules for formatting code to make it readable and professional. Following PEP 8 ensures smoother collaboration among teams, reduces errors and makes maintenance easier over time.
3. How do lists and tuples differ in Python?
Ans:
Lists are flexible and can be changed, allowing addition, modification or removal of elements. Tuples are fixed and cannot be altered once created, making them ideal for storing data that should remain constant. Both structures can hold multiple types of data but the choice depends on whether mutability is required.
4. How is memory managed in Python programs?
Ans:
Python handles memory automatically through reference counting and a built in garbage collector. Unused objects are cleared from memory to free up space. The memory manager organizes objects into generations to optimize performance and ensure efficient memory usage throughout program execution.
5. What are the commonly used built-in data types in Python?
Ans:
Python offers diverse data types for different needs, including numeric types like integers and floats, sequences like lists and tuples, text types such as strings, sets, mappings like dictionaries and Boolean values. These types allow efficient storage, retrieval and manipulation of data in programs.
6. How does Python pass arguments to functions?
Ans:
Python passes arguments by object reference. For mutable objects like lists changes inside a function affect the original object, whereas immutable objects like strings remain unchanged. This approach is often referred to as call by object reference and balances flexibility and safety in function calls.
7. What is the Global Interpreter Lock in Python?
Ans:
The GIL permits the execution of Python bytecode by a single thread at a time, even on multi core processors. While it simplifies memory management, it restricts parallel execution for CPU heavy tasks. For I/O-bound operations, this limitation has minimal impact, making Python still effective for many applications.
8. What is the difference between a module and a package in Python?
Ans:
One Python file called a module contains functions, classes or variables, while a package is a collection of modules organized in a folder with an initializer. Modules help reuse code efficiently and packages make it easier to organize large projects into structured, maintainable components.
9. What are some popular built-in libraries in Python?
Ans:
Python includes a variety of built-in libraries that simplify development, such as libraries for mathematics, date and time management, system interactions and handling structured data formats. These libraries allow developers to accomplish complex tasks without relying on external tools.
10. How can you manage memory usage effectively in Python?
Ans:
Effective memory management involves writing clean code, avoiding unnecessary object creation and relying on garbage collection. Developers can reuse variables use memory efficient constructs and leverage built in tools to monitor memory usage ensuring programs run smoothly even with large datasets.