forked from chavarera/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.MethodsInClass.py
More file actions
39 lines (28 loc) · 1.06 KB
/
2.MethodsInClass.py
File metadata and controls
39 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# every class has one method __init__() which is automatically called when the class object is created
# every class method need one parameter that is self or you can write your classname intead of self
# 1.using Self keywords
class Person():
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
def isegl(self): # this is new method defination
if self.age >= 18:
return True
else:
return False
person1 = Person('Abhi', 17, 3333)
print(person1.isegl()) # calling method using instance of class means object of class
# 2.using Class name
class Person2():
def __init__(Person2, name, age, salary):
Person2.name = name
Person2.age = age
Person2.salary = salary
def isegl(Person2): # this is new method defination
if Person2.age >= 18:
return True
else:
return False
person1 = Person('Abhi', 19, 3333)
print(person1.isegl()) # calling method using instance of class means object of class