| Basic OOP in Python | |
|
|
Author | Message |
---|
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Basic OOP in Python Mon Sep 20, 2010 8:51 am | |
| Well, this forum is empty, so I figured I would put something in here to kick-start it. Below is a basic example of OOP in Python. NOTE: ONCE AGAIN, I AM USING PORTABLE PYTHON V1.1, WHICH IS BASICALLY PYTHON V.3.0.1, SO CODING MAY DIFFER FOR DIFFERENT VERSIONS OF PYTHON!! - Code:
-
class Person: def sayHi(self): print('Hello, how are you?') p = Person() p.sayHi()
Output: Hello, how are you?
Basically, what is happening here is you are defining a new class named "Person". You are then creating a method, or action, for the instance (object) in the class "Person", in this case, you use the def(ine) command to create this. In the next block, you are telling Python to print the string "Hello, how are you?". Next, you are setting the variable "p" to mean "Person" (the class you created). Then, you are telling the class "Person" (through the variable) to perform the method "sayHi". You always have objects perform methods by using dot notation, in this case p .sayHi. There! You now have now made a basic OOP program in Python!! | |
|
| |
Excimer Sun Software
Posts : 152 Join date : 2010-05-07 Age : 31 Location : USA
| Subject: Re: Basic OOP in Python Sat Sep 25, 2010 5:44 pm | |
| Thanks for putting something here, CTI. | |
|
| |
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Re: Basic OOP in Python Mon Sep 27, 2010 1:22 pm | |
| No problem! How'd I do, ESS? | |
|
| |
Excimer Sun Software
Posts : 152 Join date : 2010-05-07 Age : 31 Location : USA
| Subject: Re: Basic OOP in Python Tue Oct 05, 2010 8:55 am | |
| Quite well. Good example code too. OOP can be a difficult thing to explain and you did a pretty good job. | |
|
| |
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Re: Basic OOP in Python Tue Oct 05, 2010 1:26 pm | |
| Thanks! I am planning to next put in a more complex program, involving this little example. | |
|
| |
Excimer Sun Software
Posts : 152 Join date : 2010-05-07 Age : 31 Location : USA
| Subject: Re: Basic OOP in Python Wed Oct 13, 2010 12:11 pm | |
| Sounds good! OOP is one of those things that just can't be explained enough. | |
|
| |
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Re: Basic OOP in Python Thu Oct 14, 2010 1:43 pm | |
| Oh, it can be explained, it just might get confusing... | |
|
| |
Excimer Sun Software
Posts : 152 Join date : 2010-05-07 Age : 31 Location : USA
| Subject: Re: Basic OOP in Python Thu Oct 14, 2010 10:55 pm | |
| Indeed...very true this is. *sagenod* | |
|
| |
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Re: Basic OOP in Python Thu Oct 21, 2010 6:12 pm | |
| But remember, young warrior, anyone can do it. It just takes practice! | |
|
| |
Excimer Sun Software
Posts : 152 Join date : 2010-05-07 Age : 31 Location : USA
| Subject: Re: Basic OOP in Python Sat Oct 23, 2010 1:27 am | |
| Yes yes, very true. Practice makes perfect, as the saying goes! Waaiit aa minute! Young warrior?!?! YOUNG warrior!!!!?!!?!??? Don't make me go dragon on you, CTI! Shrrawrrraggghhshheeeaaahhhhh!!!!!!! Śsïl utśsïluñct çśtsïluñct ültöllübt!!!!!! | |
|
| |
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Re: Basic OOP in Python Sat Oct 23, 2010 12:35 pm | |
| *shakes head* Actors... highly strung... | |
|
| |
Excimer Sun Software
Posts : 152 Join date : 2010-05-07 Age : 31 Location : USA
| Subject: Re: Basic OOP in Python Sun Oct 24, 2010 10:03 pm | |
| | |
|
| |
The Fellow Admin
Posts : 100 Join date : 2010-04-28 Age : 31 Location : In my head, dreaming up how to shake up the world
| Subject: Re: Basic OOP in Python Sun Oct 24, 2010 10:08 pm | |
| This topic has gone farrrrrrrrr to deep into a tangent. Please change this topic about Basic OOP in Python. | |
|
| |
Compu-Teck Inc.
Posts : 80 Join date : 2010-04-29 Age : 31
| Subject: Re: Basic OOP in Python Tue Oct 26, 2010 8:38 am | |
| | |
|
| |
Sponsored content
| Subject: Re: Basic OOP in Python | |
| |
|
| |
| Basic OOP in Python | |
|