Wednesday 11 December 2019

Python - Day Twenty Eight (December)

WHAT I DID TODAY:

Today I worked on the new unit called, "Introduction to Classes." There were 18 lessons today and I did 9 of them. So far I learned about a new function or code. It's called 'classes.' 


COMPLETED


Within the 9 lessons, I obviously did exercises after learning the new function. It was a bit different this time because each lesson was like a new step to the same exercise. I don't know if that makes sense but basically it was just the same exercise that I worked on, while adding new things/codes I learned.


  • The first step was to just set the base of the exercise. The code below does not do anything and is just the start.
STEP 1

  • The second step was to get the code started. I added some 'meaning' to the function below by adding in def. Since there's also new and unfamiliar codes in this exercise, I will be explaining them below in the next section.
STEP 2

  • This step is to 'give the object' a name. The 'name' refers to the created object's name by typing self.name = name .. 
STEP 3


  • This final step was to add a method, description, and animal class. I had to use two different print statements, to print out the name and age of an animal.
STEP 4

(THERE WAS LITTLE STEPS BEFORE STEP 4 BUT I THOUGHT IT WAS UNNECESSARY SO I SHOWED STEP 4 AS THE NEXT STEP)




WHAT I LEARNED:


Today I learned about the class function, which is the main topic of the whole unit as said in the title.


  • The first thing I learned was of course the actual class function itself. It consists of the class keyword, the name of the class, and the class from which the new class inherits in parentheses. The format goes like this 'class NewClass(object) : What this does is basically just gives power and abilities of a Python object. (User-defined Python class names start with a capital letter.)
CLASS FORMAT EXAMPLE


  • The second thing I learned was the __init__() function. This function is mandatory and very much required for classes, as it utilizes the objects it creates. It's basically considered as the function as a thing that 'boots up' each object the class creates.
__INIT__ EXAMPLE


(KEEP IN MIND THAT I AM USING THE SAME IMAGE FROM ABOVE FOR __INIT__ BECAUSE THIS WAS BASICALLY THE ONLY TIME AND PHOTO THAT WAS PRESENT)




WHAT I WILL BE DOING TOMORROW / NEXT TIME:


Next time I will finish up the outstanding lessons that I didn't get to finish today.

NEXT LESSONS



No comments:

Post a Comment

Adobe Photoshop - Day 10 (June Final Post)

WHAT I DID TODAY / WHAT I LEARNED: For my final project, I thought for a while about what I could do. Then I remembered a while back I saw ...