Classes in Python
#day3 of #100daysofcode
Earlier I decided to continue with Deep Q learning which I was doing yesterday but then I decided to brush up classes in python. Classes make it easy to maintain and work with the code. Therefore, I thought of revising them. I had learned them earlier and knew the concept but I never used them much.
I have mostly done my work using functions. I can say till now I have used python as a functional language. Functions are great but now as I am working with the Deep Q learning model I realized that it would be better and easy to work with the classes. Moreover, the code remains neat and clean though python code is already neat and clean thanks to the indentation.
Now I will be handling my work with classes. OOP(Object Oriented Programming) has its benefits. I watched this youtube series which is awesome and it cleared my concept. Everything is very well covered in this series. I could say today was the day to clear my basics. I liked it and enjoyed it. I wrote some practice code to make myself comfortable. I advise you to watch the videos and then write the code. Do not copy and paste it. Write it yourself. After doing that play with it. What I mean by play with it is that you should make some changes to it and observe the results. Try different things. Think like what would be the output if it will be like this and that. Check out various situations when the code is giving an error. Knowing why and what error your code is giving is also very helpful.
I will give you a brief idea about the various concepts you will find in the series and classes in python.
- How to create a class?
- What is the use of __init__ function? (it is used to initialize the class, works like the constructor in C/C++)
- What are static methods and how to create one?
- What are class methods and how to create one?
- What are decorators and how to work with them?
- What are magic or dunder or Special methods?
- How to inherit a class and reuse its code?
These are some of the concepts you must look at when learning about classes. You should practice them after learning them. It was fun to explore the classes in detail. Really OOP is very strong and help. I will try to shift my coding style to classes or OOP. You should also try it once.
Github: https://github.com/karanjakhar/100-days-of-code/tree/master/day3
Hopefully tomorrow I will continue with Deep Q learning if something less will not pop up. See you tomorrow :)