Have you ever wondered why in most programming languages you learn variables first? Well! Guess what, you are not alone! Although I would think that’s an important part to store information that you might use later, For some reason whatever you learn first stick to your brain better. I would think that you learn objects first in an Object Oriented Programming Language. With that said, in Python everything is an Object. Now!! Objects in other languages, live inside classes or God knows where. Any way let’s just say for a minute that we want to create pages of books in Python. So in other words the book would be the class and the pages would belong to the book. So in code to do the class Book, just type class BookOfSanti:
If I was to create pages for my book then I would have to have an init method under my class remember about indentation In python everything that belongs to something has to be indented the same. Here is some info about indentation: https://www.geeksforgeeks.org/indentation-in-python/
Chances are that if your code is not working correctly, there might be an indentation error or you just typed something wrong. The way you type stuff in python Matters. Class is not the same as class. true is not the same as True. Under each class we want the init method, or Dunder init method, “Dunder for double underscore” so if you want to write the init method it would look as follows__init__(self): underscore, underscore, follow by the word init follow by underscore, underscore, left parentheses, the word self then the right parentheses then the colon. That’s the syntax for the init method if you want to write helicopter instead of self go for it, want to put there ball instead of self go for it. However common syntax accross python programmers is to use self, might as well just if you can’t understand it think about itself whatever object you create is going to refer to the self in the init method when create an Object. So if I was to create a book page the method would look like
def __init__(self, page):
self.page = page
page_1 = BookOfSanti(1)
A lot to talk about it but to do the page_1 object we got to create the name of the variable which will be page_1 followed by the equal sign then the name of the class BookOfSanti followed by the left parentheses I am telling python I want to assign number 1 to the variable page_1 then right parentheses. Think of a variable as something you Might need down the road. So if you want to store a value which is in this case 1 to the variable page_1 you have to follow that sintax. any way, there is this very good video that talks about classes and explain the self keyword inside the init method as well as coding examples. Here is the link. https://m.youtube.com/watch?v=ZDa-Z5JzLYM
I really don’t want to bother you to death, so learn about objects and classes. Learn the language for example instantiation that’s such a fancy word for making something out of the class so if I was to say I am instantiating page_1 out of the BookOfSanti that means I am creating an object page_1 out of the class BookOfSanti. If I was to say I am instantiating yummy food from cooking that means I am creating yummy food from the class cooking. I like the YouTube channel for Alex Lee he is a java guy but in Object Oriented programming the wording is the same across most languages. Any way. That’s a lot for now! Hope you learn something and practice watch that YouTube video and code! I am not going to hold your hand while in rolling blades, that means that you have to learn how to stay on top of what you do at all times, so learn how to display to the user the object that you created hint, hint the print method. What did you learn from the Corey Schafer you tube video? Ttyl take it easy and don’t try to learn too much at one time!
Here is a list of people that you can follow or find on You Tube that teach Python: Al Sweigart, Anaconda Inc, Chris Hawkes, Christian Thompson, Clever Programer, Code with Harry, Corey Shafer, CS Dojo, Derek Banas, Data School, FreeCodeCamp, Pretty Printed, Programming With Mosh, PyData, Real Python, Sentdex, Socratica, Telusko, The New Boston, Caleb Curry, Traversy Media, and others. One site I like is w3schools.com.Please comment if you have any different channels or resources to learn Python, what would be something that you think should be taught first?