Professional Documents
Culture Documents
AND TECHNOLOGY
MARDAN
LAB TASKS – 02
dict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(dict)
Output:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
2) FUNCTION:
Calling a Function:
def my_function():
print("Hello from a function")
my_function()
Output:
Hello from a function
3) CLASS:
class MyClass:
x=5
print(MyClass)
Output:
<class '__main__.MyClass'>
4) INHERITANCE:
class Person(object):
# Constructor
def __init__(self, name):
self.name = name
# To get name
def getName(self):
return self.name
# To check if this person is an employee
def isEmployee(self):
return False
# Inherited or Subclass (Note Person in bracket)
class Employee(Person):
# Here we return true
def isEmployee(self):
return True
# Driver code
emp = Person("Haroon") # An Object of Person
print(emp.getName(), emp.isEmployee())
emp = Employee("Haroon1") # An Object of Employee
print(emp.getName(), emp.isEmployee())
Output:
Haroon
Haroon1
5) Reading File: