Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c65f47

Browse files
authored
Create main.py
1 parent 4fb5a78 commit 8c65f47

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

β€ŽOOP Example/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Class Creation
2+
class Person:
3+
# Initialization function (when you create an object this named initialization)
4+
def __init__(self,name,age):
5+
# changing objects attributes to arguments that we enter when calling an class to create an object
6+
self.name = name
7+
self.age = age
8+
9+
# String function that returns a string that will be returned if you will print class
10+
# Without __str__(): <__main__.Person object at 0x000001AC025E7230>
11+
# With __str__():
12+
def __str__(self):
13+
return f'Name: {self.name}. Age: {self.age}'
14+
15+
# Creating an object using class
16+
p = Person("John",21) # you can change the values and create some other methods in class
17+
print(p)
18+
19+
# Output:
20+
# Name: John. Age: 21

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /