Python CLASS VARIABLES explained easy! 🎓
# class variables = Shared among all instances of a class
# Defined outside the constructor
# Allow you to share data among all objects created from that class
class Student:
class_year = 2025
num_students = 0
def __init__(self, name, age):
self.name = name
self.age = age
Student.num_students += 1
student1 = Student("Spongebob", 30)
student2 = Student("Patrick", 35)
student3 = Student("Squidward", 55)
student4 = Student("Sandy", 27)
print(f"My graduating class of {Student.class_year} has {Student.num_students} students")
print(student1.name)
print(student2.name)
print(student3.name)
print(student4.name)
Видео Python CLASS VARIABLES explained easy! 🎓 канала Bro Code
# Defined outside the constructor
# Allow you to share data among all objects created from that class
class Student:
class_year = 2025
num_students = 0
def __init__(self, name, age):
self.name = name
self.age = age
Student.num_students += 1
student1 = Student("Spongebob", 30)
student2 = Student("Patrick", 35)
student3 = Student("Squidward", 55)
student4 = Student("Sandy", 27)
print(f"My graduating class of {Student.class_year} has {Student.num_students} students")
print(student1.name)
print(student2.name)
print(student3.name)
print(student4.name)
Видео Python CLASS VARIABLES explained easy! 🎓 канала Bro Code
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
PHP while loops explainedMongoDB how to find documentsMongoDB sorting and limiting explainedLearn Python DECORATORS in 7 minutes! 🎊JavaFX FlowPane 🌊PHP string functions are awesomePHP how to insert into MySQL databasePython SORTING is... quite something! 🔀Learn Python MAP() in 3 minutes! 🗺️Learn Python CLASS METHODS in 6 minutes! 🏫Learn Python DATES & TIMES in 6 minutes! 📅CSS shadow (#6) 👥PHP how to sanitize/validate inputFormat currency EASY in JavaScript 💲Python MULTIPLE INHERITANCE is easy! 🐟Let's code a HANGMAN GAME in Python! 🕺PHP variables and data typesPython PyQt5 add CSS-like properties easy! 🎨Python PyQt5 CHECKBOXES are easy! ✅MongoDB logical operators explained