Programs
1. Calculate the Area of a Rectangle and Triangle 2. Check Whether a Number is Even or Odd 3. Generate Fibonacci Sequence of Length N 4. Check Whether the Number…
1. Calculate the Area of a Rectangle and Triangle 2. Check Whether a Number is Even or Odd 3. Generate Fibonacci Sequence of Length N 4. Check Whether the Number…
Printing of Objects Example (from 17.6): This provides a human-readable output when printing an object. Objects Are Mutable Example (from 15.5): Modified values: Functions can also modify objects: Calling: This…
Explain __init__() and __str__() methods with examples. Discuss type-based dispatch in Python Answer:- __init__() Method Example (from 17.5): Usage: This sets time.hour = 9, time.minute = 45, and time.second =…
i) Prototyping and Planning Prototyping and planning are two different approaches to software development. Prototype and Patch Approach (from 16.4): This approach is helpful when the problem is not fully…
Pure Function A pure function does not modify any of the objects it receives as arguments. It only returns a new value. Example (from 16.2): Usage: This function does not…
1. break Statement The break statement is used to exit the loop immediately, even if the loop condition is still True. Example: Output: Explanation:The loop runs from 1 to 9,…
i) isinstance() Used to check if an object is an instance of a specific class. Example: This returns True if p is an instance of the Point class. ii) hasattr()…
Python is an object-oriented programming language. Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which can contain data (attributes) and code (methods). The following are…
1. print() Function The print() function in Python is used to display text or output on the screen. 2. input() Function The input() function takes user input during program execution.…
A class is a programmer-defined type. A class definition creates a new class object. Defining a class: Creating an instance: Assigning attributes: Accessing attributes: Using in expressions: