0x08 Python - More Classes and Objects
0x08 Python - More Classes and Objects
0x08 Python -
More Classes
and Objects
python- Programming
TABLE OF CONTENTS
01 02
Overview Learning
topics Objectives
03 04
Quiz hands on lab
questions practice
01
OVERVIEW topics
Topics
https://t.me/alx_2023
python
Programming
Topics
Slides On Telegram
alx_2023ch
02
Learning Objectives
What is a class attribute
class MyClass:
class_attribute = "I am a class attribute"
class Car:
# Class attribute
fuel_type = "Gasoline"
Decorator: To define a static method, you use the @staticmethod decorator above
the method definition.
No access to instance-specific data: Static methods don't take the self parameter
as their first argument, which is a convention for instance methods. This means
they cannot access or modify instance attributes.
What is a static method
class MathUtils:
@staticmethod
def add(x, y):
return x + y
@staticmethod
def subtract(x, y):
return x - y
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def __str__(self):
return f"{self.name}, {self.age} years old"
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def __repr__(self):
return f"Person('{self.name}', {self.age})"
Share
To let the others know more
Thanks