From 5443c8ec21f89c0aec4bc433f2222121d7b8dac6 Mon Sep 17 00:00:00 2001 From: Nikita Antropov Date: Fri, 17 Jan 2025 22:19:01 +0300 Subject: [PATCH 1/2] Added oop_example.py file --- other/oop_example.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 other/oop_example.py diff --git a/other/oop_example.py b/other/oop_example.py new file mode 100644 index 000000000000..bba26f85af5e --- /dev/null +++ b/other/oop_example.py @@ -0,0 +1,20 @@ +# 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 + self.name = name + self.age = age + + # String function that returns a string that will be returned if you will print class + # 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 \ No newline at end of file From 272d6248a4b990a22fccf5861087115c131e5a99 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:21:50 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/oop_example.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/other/oop_example.py b/other/oop_example.py index bba26f85af5e..1a2dc3369376 100644 --- a/other/oop_example.py +++ b/other/oop_example.py @@ -1,20 +1,21 @@ # Class Creation class Person: # Initialization function (when you create an object this named initialization) - def __init__(self,name,age): + def __init__(self, name, age): # changing objects attributes to arguments that we enter when calling an class to create an object self.name = name self.age = age # String function that returns a string that will be returned if you will print class # Without __str__(): <__main__.Person object at 0x000001AC025E7230> - # With __str__(): + # With __str__(): def __str__(self): - return f'Name: {self.name}. Age: {self.age}' - + return f"Name: {self.name}. Age: {self.age}" + + # Creating an object using class -p = Person("John",21) +p = Person("John", 21) print(p) # Output: -# Name: John. Age: 21 \ No newline at end of file +# Name: John. Age: 21