Classes in Python

Classes in Python

When I hear "Words" by Bayonne, I think of the American Hill. The American Hill is my favourite place on earth and it is a hill near my house in Luxembourg.

American flag.

I call it the American Hill because when I am on there, way way way high up, I feel like I am in America. I LOVE that place.

I love Luxembourg. 

I love the energy infrastrcure.

Types

Just reviewing the obvious on types. There are different types and different things that you can do with them. The type of data that you are using will affect the methods you can use on it and so on, for examples, strings are not divisible, and you cannot use .get() on an integer.

Classes

"A "class" is a template for a data type. It describes the kinds of information that class will hold and how a programmer with interact with that data." You define a class by using the word "class" and it is recommended to capitalise them.

Instantiation

"A class doesn't accomplish anything simply by being defined. A class must be instantiated. In other words, we must create an instance of the class, in order to breathe life into the schematic."

Instantiating a class looks like CALLING A FUNCTION. 

cool_instance = CoolClass()

So there's no "new"!!!!!!!! Arrrrrgh this is different to JavaScript!

Class Variables

ARRRRRRRRGH

This is like my 10th or my 17th day in a row without a break I don't know. I can't wait to relax a bit. Anyway - classes that have repeat data in them may have "class variables".

Methods

From Codedacemy = """

Methods are functions that are defined as part of a class.
The first argument in a mathod is always the object that is calling that method.
Convention recommends that we name this first argument self [hmmmm - my meditation friends would like that!]
Methods always have at least THIS ONE ARGUMENT.

"""

Methods always need to have the (self) argument inside of them when they are defined - but they do not need it when they are called. This is because "when you call a method it automatically passes the object calling the method as the first argument."

Methods can also take more arguments than just self , but it is important to always have the self  argument there anyway.

Constructors

Omg I am so exhausted right let's keep doing this ✅

Comments

Popular posts from this blog

Hello World

Yosemite

Where To Hide A Star