griimnak
You're a slave to the money then you die
What is Object Oriented Code?
A programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.
Why should I write Object Oriented Code?
Object Oriented Code makes it easier for you to implement or remove functions, call objects and organize your code. Writing Object Oriented Code is considered good practice, especialy if you're new to the language.
Not Object Oriented:
Object Oriented:
What's difference between these two examples?
Online references
OOP Python article:
Python OOP tutorials:
Offical Python documentation for OOP:
If this helped ya out leave a like, man. cheers.
A programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.
Why should I write Object Oriented Code?
Object Oriented Code makes it easier for you to implement or remove functions, call objects and organize your code. Writing Object Oriented Code is considered good practice, especialy if you're new to the language.
Not Object Oriented:
PHP:
#folder.file
setting1 = 'some text'
setting2 = 'more text'
PHP:
#calling variables example
import folder.file as config
new_var = config.setting1
another_var = config.setting2
Object Oriented:
PHP:
#folder.file
class settings(object):
def __init__(self):
self.setting1 = 'some text'
self.setting2 = 'more text'
def some_function(self):
#this is a function
PHP:
from folder.file import settings
config = settings() #store your object in this variable so you can call it
new_var = config.setting1
another_var = config.setting2
What's difference between these two examples?
- class settings(object):
Makes an object.
- def some_function(self):
Makes a function. self is used to pass the function to the object.
- def __init__(self):
This one is interesting. Anything that you'd want to call from the class itself from another location would go under this function. It makes whatever is under that function public.
- self.setting1 = 'some text'
Why the self.? If you were to just put setting1 under the __init__ function it wouldn't work, because setting1 is just a local variable. Adding self. to it makes it bound to that object, thus allowing you to call it elsewhere.
Online references
OOP Python article:
You must be registered for see links
(I really recommend this)Python OOP tutorials:
You must be registered for see links
Offical Python documentation for OOP:
You must be registered for see links
If this helped ya out leave a like, man. cheers.
Last edited: