python1
python1
3. **Broadcasting**:
Q.Difff Bet List And Tuple Q.Design a class student with data members :
name, roll no., department,mobile no. Create
List Tuple List Tuple suitable methods for reading and printing student
Lists are mutable Tuples Lists are mutable Tuples
are immutable are immutable information.
The implication of The implication of class Student:
iterations is Time- iterations is Time-
consuming consuming def __init__(self):
The implication of The implication of
iterations is iterations is self.name = ""
comparatively Faster comparatively Faster self.roll_no = ""
self.department = ""
self.mobile_no = ""
Q. description of the `open()` and `write()`
def read_student_info(self):
functions in Python, along with examples.
self.name = input("Enter student name: ")
### `open()`
self.roll_no = input("Enter roll number: ")
The `open()` function is used to open a file in Python.
It returns a file object, which can then be used to self.department = input("Enter department: ")
read from or write to the file. The `open()` function
has the following syntax: self.mobile_no = input("Enter mobile number: ")
```python student.read_student_info()
file.close()
Q.code for following output def method2(self):
Cursor=[:] BaseClass1.__init__(self)
Cursor=[2:2] BaseClass2.__init__(self)
Thus, the corrected outputs for the operations are: print("Method from DerivedClass")
derived_object = DerivedClass()
Cursor = Cursor[:3] -> 'pyt'
Cursor = Cursor[3:] -> 'hon' derived class
Cursor = Cursor[:] -> 'python'
Cursor = Cursor[2:2] -> '' derived_object.method1()
Cursor = Cursor[-1] -> 'n' derived_object.method2()
Cursor = Cursor[1] -> 'y'
derived_object.method3()
print(derived_object.str1)
Q. code for generate radom num 10 to 50 using
numpy lib print(derived_object.str2)
import numpy as np
# Generate a random integer between 10 (inclusive) Q.Explain any four file modes in Python.
and 51 (exclusive)
print(random_number)
class BaseClass1:
def __init__(self):
self.str1 = "BaseClass1"
print("BaseClass1 initialized")
def method1(self):
class BaseClass2:
def __init__(self):
self.str2 = "BaseClass2"
print("BaseClass2 initialized")