A common mistake to avoid when using object-oriented programming is incorrectly using class variables instead of instance variables. In this video, learn how to create class variables and instance variables properly when defining classes.
- [Instructor] A common mistake to avoid when using … object oriented programming is incorrectly using … class variables instead of instance variables. … It's important to ensure that class variables … and instance variables are used properly. … I'll be walking through an example in this video. … Let's say that I'm designing an online game and I've started … defining the class named, player. … And my goal is to define it in such a way that each instance … of the player class corresponds to a player of the game … and contains relevant information for that player. … As you can see, word bank is created as a class variable, … which is the right choice … as all players must have access to that word bank … and they cannot change the word bank. … Next, points is created as another class variable … and is supposed to keep track … of the corresponding player's points. … Then alive is created as a class variable and is supposed … to keep track of whether the player is alive. … Afterwards in the constructor of the player class, …
Skill Level Intermediate
1. Avoid Mistakes in Coding Practices
2. Avoid Mistakes in Structuring Code
3. Avoid Mistakes in Handling Data
4. Avoid Mistakes in Machine Learning
Using redundant features1m 45s
Get started with Python1m 7s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.