joeyajames / Python

Python code for YouTube videos.
MIT License
1.64k stars 1.35k forks source link

Update building our first class.py #132

Open nikitapandeyy opened 1 year ago

nikitapandeyy commented 1 year ago

The comment before the class definition is misleading. It says "Below is the method how classes are defined" but it's not a method, it's an example of how to define a class.

The class definition is incomplete. It only has the "pass" statement, which means it doesn't have any attributes or methods.

The variable names "Varun" and "larry" should start with a lowercase letter according to Python naming conventions.

The attributes are being added dynamically to the objects, which is not a good practice. It's better to define the attributes in the class definition.

The attribute "subjects" is being assigned a list, which is fine, but the attribute "std" is being assigned an integer and a float value in different instances, which could cause issues if the class methods rely on those values being of the same type.

Aashray24092000 commented 1 year ago

A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.

An object is created using the constructor of the class. This object will then be called the instance of the class. In Python we create instances in the following manner

instance=class(parameter)