Assignment 1
Assignment 1
Ans. Python 2.x and Python 3.x are two major versions of Python, with Python 3.x being a more
modern iteration. Python 2.x is legacy software and is no longer actively maintained as of
January 1, 2020. One key difference is the handling of strings: in Python 2.x, strings are ASCII by
default, while Python 3.x uses Unicode, which makes it more versatile for modern applications.
The print statement in Python 2.x was changed to a print() function in Python 3.x, making the
syntax consistent with other functions. Additionally, Python 3.x introduced features like better
integer division using the // operator and improved error handling. Overall, Python 3.x
encourages cleaner and more future-proof code.
Ans. PVM stands for Python Virtual Machine. It is a part of Python’s runtime environment
responsible for executing the compiled Python bytecode. When Python code is executed, it is first
converted into intermediate bytecode by the Python interpreter, which is then executed by the PVM.
The PVM is platform-independent and ensures Python code runs uniformly across different operating
systems.
Ans. A compiler translates the entire source code of a program into machine code before
execution, whereas an interpreter translates and executes the code line by line. Compilers are
generally faster in execution since the entire code is pre-compiled, but errors are harder to debug
because they are reported after compilation. Interpreters, on the other hand, provide immediate
feedback for errors, making debugging easier but at the cost of slower execution due to real-time
interpretation. Compilers are better for applications requiring high performance, as they produce
optimized machine code. Interpreters are more suitable for development and scripting environments
where immediate feedback and portability are prioritized. Python, for example, uses an interpreter,
making it excellent for rapid prototyping and scripting.
Ans. Keywords in Python are reserved words that have specific meanings and cannot be used as
identifiers. Examples include if, else, while, for, def, return, class, try, except, True, False, and None.
As of Python 3.10, there are 36 keywords, and they are case-sensitive.
Ans. PEP stands for Python Enhancement Proposal. It is a design document providing information to
the Python community or describing new features for Python. PEPs are critical in the decision-
making process for Python’s evolution, ensuring transparency and collaboration among developers.
Ans. PEP 8 is the style guide for Python code, outlining conventions for code layout, naming, and
formatting to ensure consistency and readability. It focuses on aspects like indentation, line length,
and naming conventions. PEP 9, on the other hand, is a document detailing guidelines for proposing
and maintaining Python library modules. It is less about coding style and more about the structure
and lifecycle of library modules within Python’s ecosystem.