Python is a high level, purpose-dynamic programming language that has a focus on readability. In order to c efficiently and begin meaningful practice, a basic grasp of core programmatic concepts is needed. Python is an object-oriented language, meaning data and functions that are related are bound to an object structure, which can then be reused. This modularity promotes efficient and reusable code which helps minimise redundancies. Two of the most important concepts in object-oriented programming are:
How to use Classes and Object in Python
i) Classes – This is the blueprint for an object, created by the programmer. This defines a set of attributes that will characterise any object instantiated from this class. For example, a House class may outline the size, shape and color properties of a house, along with any associated functions i.e open the front door, close the window etc. Classes are what make object-oriented programming a powerful and flexible programming model used across most popular languages.
ii) Objects – This is an instance of the class, where it is manifested in the program as a usable variable. For example, we could create an instance of our House class with a certain set of properties:
MyNewHouse = House (yellow, egg, large)
The above creates the MyNewHouse variable (which is an instantiation of the House class) and uses the yellow, egg, and large properties to define the color, shape and size respectively. The user can create as many instantiations of this class as they like, each with differing properties.
The concept of objects and object oriented design are among some of the most difficult to grasp in the entire process of learning to code, and they are best understood through implementation and practice. It is advisable that a learner should follow this learning with interactive tutorials, such as those available at khanacademy.org and codingdojo.com.