Python Paper 2

 a) Define a class. How is class members accessed in Python?

class MyClass:

    class_variable = "I am a class variable"


print(MyClass.class_variable)  # Access using class name

obj = MyClass()

print(obj.class_variable)  # Access using an instance
-----------------------------------------------------------------------------------------------------------------------------

b ). Explain the utility of assert statement
def divide(a, b):

    assert b != 0, "Denominator must not be zero"

    return a / b


result = divide(10, 2)  # Works fine

result = divide(10, 0)  # Raises AssertionError: Denominator must not be zero
---------------------------------------------------------------------------------------------------------------------------

2) Explain the steps of installing Python. Discuss the features and limitations of Python programming language.  

Steps to Install Python

To install Python on your computer, follow these steps:


1. Download Python Installer

  • Go to the official Python website: https://www.python.org/.
  • Navigate to the Downloads section.
  • Select the appropriate installer for your operating system:
    • Windows: .exe file
    • macOS: .pkg file
    • Linux: Most Linux distributions come with Python pre-installed, but you can download updated versions if needed.

2. Install Python on Your System

  • For Windows:

    1. Run the downloaded .exe file.
    2. In the installation wizard, check the box "Add Python to PATH" (important for accessing Python via the command line).
    3. Click "Install Now" or choose "Customize Installation" for advanced settings.
    4. Once the installation is complete, verify it by running python --version or python in Command Prompt.
  • For macOS:

    1. Open the downloaded .pkg file and follow the installation prompts.
    2. Verify the installation by running python3 --version in the terminal.
  • For Linux:

    • Install Python using the package manager:
      sudo apt update
      sudo apt install python3
      
    • Verify the installation:
      python3 --version
      

3. Verify Installation

  • Open a terminal or command prompt.
  • Type python or python3 to start the Python interpreter.
  • Alternatively, run python --version or python3 --version to check the installed version.

4. Install a Code Editor or IDE (Optional)

  • While Python can be written in any text editor, using an IDE or code editor improves productivity. Popular options include:
    • PyCharm
    • Visual Studio Code
    • Jupyter Notebook
    • IDLE (comes pre-installed with Python)

-----------------------------------------------------------------------------------------------------------




Comments

Popular posts from this blog

Keyword , Identifier, Indentation, Comments & Documentation

DSA Lab 8 program

DSA Lab 7 Program