Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn class variables in 8 minutes! ๐ŸŽ“
Play lesson

Python tutorial for beginners ๐Ÿ - Learn class variables in 8 minutes! ๐ŸŽ“

4.0 (0)
8 learners

What you'll learn

This course includes

  • 14.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

# 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)

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere