Skip to content

Added oop_example.py file #12528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions other/oop_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Class Creation
class Person:
# Initialization function (when you create an object this named initialization)
def __init__(self, name, age):
# changing objects attributes to arguments that we enter when calling an class to create an object

Check failure on line 5 in other/oop_example.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/oop_example.py:5:89: E501 Line too long (106 > 88)
self.name = name
self.age = age

# String function that returns a string that will be returned if you will print class

Check failure on line 9 in other/oop_example.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/oop_example.py:9:89: E501 Line too long (89 > 88)
# Without __str__(): <__main__.Person object at 0x000001AC025E7230>
# With __str__():
def __str__(self):
return f"Name: {self.name}. Age: {self.age}"


# Creating an object using class
p = Person("John", 21)
print(p)

# Output:
# Name: John. Age: 21
Loading