-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclassobject.py
More file actions
61 lines (41 loc) · 902 Bytes
/
classobject.py
File metadata and controls
61 lines (41 loc) · 902 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#Create a Class
class MyClass:
x = 5
#Create Object
p1 = MyClass()
print(p1.x)
#The __init__() Function
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
print(p1.name)
print(p1.age)
#Object Methods
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("John", 36)
p1.myfunc()
#The self Parameter
class Person:
def __init__(mysillyobject, name, age):
mysillyobject.name = name
mysillyobject.age = age
def myfunc(abc):
print("Hello my name is " + abc.name)
p1 = Person("John", 36)
p1.myfunc()
#Modify Object Properties
p1.age = 40
#Delete Object Properties
del p1.age
#Delete Objects
del p1
# The pass Statement
class Person:
pass