File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 1
1
# Class Creation
2
2
class Person :
3
3
# Initialization function (when you create an object this named initialization)
4
- def __init__ (self ,name ,age ):
4
+ def __init__ (self , name , age ):
5
5
# changing objects attributes to arguments that we enter when calling an class to create an object
6
6
self .name = name
7
7
self .age = age
8
8
9
9
# String function that returns a string that will be returned if you will print class
10
10
# Without __str__(): <__main__.Person object at 0x000001AC025E7230>
11
- # With __str__():
11
+ # With __str__():
12
12
def __str__ (self ):
13
- return f'Name: { self .name } . Age: { self .age } '
14
-
13
+ return f"Name: { self .name } . Age: { self .age } "
14
+
15
+
15
16
# Creating an object using class
16
- p = Person ("John" ,21 )
17
+ p = Person ("John" , 21 )
17
18
print (p )
18
19
19
20
# Output:
20
- # Name: John. Age: 21
21
+ # Name: John. Age: 21
You can’t perform that action at this time.
0 commit comments