Imagine a bunch of variables and functions glued together into one functional unit, and which you can copy into multiple instances and modify them individually as much as you like. That's a class.
class Dick(object):
""" Docstring? MORE LIKE COCKSTRING AHAHAHA """
def __init__(self):
""" Define my cock """
self.cocks = "hello world!"
def penis(self):
""" Print my cock """
print self.cocks
a = Dick()
a.penis()
# redefine the penis
a.cocks = "nigger"
a.penis()
b = Dick()
# note that a and b have a different cock.
print "a's cock:", a.cocks
print "b's cock:", b.cocks
Also classes can be based on other classes:
class Anus(Dick):
def __init__(self):
""" This replaces the __init__ method of Dick """
self.cocks = "faggot"
c = Anus()
c.penis()
By the way, those strings inside the class will show when you use help(Anus). The first, unbound string in a class, file or function automatically becomes the docstring that describes it.
Help on module prog:
NAME
prog
FILE
path/prog.py
CLASSES
__builtin__.object
Dick
Anus
class Anus(Dick)
| Method resolution order:
| Anus
| Dick
| __builtin__.object
|
| Methods defined here:
|
| __init__(self)
| This replaces the __init__ method of Dick
|
| ----------------------------------------------------------------------
| Methods inherited from Dick:
|
| penis(self)
| Print my cock
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Dick:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class Dick(__builtin__.object)
| Docstring? MORE LIKE COCKSTRING AHAHAHA
|
| Methods defined here:
|
| __init__(self)
| Define my cock
|
| penis(self)
| Print my cock
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
DATA
a = <test.Dick object>
b = <test.Dick object>
c = <test.Anus object>
Name:
Anonymous2012-08-15 14:02
DATA
a = <prog.Dick object>
b = <prog.Dick object>
c = <prog.Anus object>
yes it is my first language. I am usually on the imageboards.
Name:
Anonymous2012-08-15 21:56
The only way to learn OOP is to actually do it. Don't waste time reading about it. Copy someone's Dog class and make it bark, walk, sit, name it, give it 5 legs, etc. Extend the class, change up the class structure so that Dog inherits from Pet, etc. Learn what concepts those big words were trying to convey.
As long as you're playing with objects, you're learning how to handle them. Slowly but surely you'll understand WHY you use a class and you'll KNOW (how/when) to use them. But you have to write them, so go make the Dog bark.
Name:
Jeremy2012-08-15 22:04
Okay, Ill make the dog shit too :D.
Name:
Anonymous2012-08-15 22:05
The only way to learn MY ANUS is to actually do MY ANUS. Don't waste time reading about MY ANUS. Copy MY ANUS class and make it MY ANUS, MY ANUS, MY ANUS, name it, give it 5 MY ANUSs, etc. Extend MY ANUS, change up MY ANUS structure so MY ANUS inherits from MY ANUS, etc. Learn what concepts those big MY ANUS were trying to convey.
As long as you're playing with MY ANUS, you're learning how to handle MY ANUS. Slowly but surely you'll understand WHY you use MY ANUS and you'll KNOW (how/when) to use MY ANUS. But you have to write MY ANUS, so go make MY ANUS bark.
So you come from the imageboards. I'll help you anyway, but please fuck off back wherever you came from, please.
A class is like a template. Let's say I'm an inventor and I'm trying to invent inventions. I decided to make some stupid contraction that throws projectiles. I'll call it a catapult.
What the hell is this ``catapool" shit anyway? Well, what can I say. It has uh, wheels, and a silly rod. And maybe a maximum projectile weight.
But not all catapools have the same number of wheels, and not all catapults have rods of the same length. Hell, they might be even made of another material. They might even lack wheels. These are going to be the properties of my new invention.
So my template looks like this:
Template for a catapult:
Wheels [ ]
Rod length [ ]
Material [ ]
Maximum projectile weight [ ]
See how those [ ]s were left empty? It's because this is just a template. When you build an actual catapult, you're going to use this template as a base, and the actual catapult will fill these blanks according on the... well, actual catapult.
Roman catapult #1, made from Template for a catapult:
Wheels [4]
Rod length [2m]
Material [Wood]
Maximum projectile weight [5Kg]
Roman catapult #2, made from Template for a catapult:
Wheels [4]
Rod length [2m]
Material [Wood]
Maximum projectile weight [5Kg]
Roman elite catapult #10, made from Template for a catapult:
Wheels [10]
Rod length [4m]
Material [Steel]
Maximum projectile weight [50Kg]
See how the actual catapults share the template? And you can put whatever you want in the []s.
* Templates are usually called classes
* Properties are usually called member variables
* Behaviors are usually called methods
* The actual object made from a template is, well, called an object
* Python is fucking shit
* Read some book about OOP concepts in Java, it's going to be a lot easier than this FIOC piece of shit.
* Java is fucking shit too, it's only useful for learning OOP concepts
And now, go back to your home board and never come back. I'll fucking kill you if you ever bring one of your fellow imageboard shitposting le reddit retards here.