HomePortalFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 Basic OOP in Python

Go down 
AuthorMessage
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: 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!!
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic OOP in Python   Sat Sep 25, 2010 5:44 pm

Thanks for putting something here, CTI.
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic OOP in Python   Mon Sep 27, 2010 1:22 pm

No problem! How'd I do, ESS?
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: 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. Smile
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: 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.
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: 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.
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic OOP in Python   Thu Oct 14, 2010 1:43 pm

Oh, it can be explained, it just might get confusing...
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic OOP in Python   Thu Oct 14, 2010 10:55 pm

Indeed...very true this is. *sagenod*
Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic OOP in Python   Thu Oct 21, 2010 6:12 pm

But remember, young warrior, anyone can do it. It just takes practice!
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: 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!!!!?!!?!??? Evil or Very Mad Don't make me go dragon on you, CTI! Shrrawrrraggghhshheeeaaahhhhh!!!!!!! Śsïl utśsïluñct çśtsïluñct ültöllübt!!!!!!

Back to top Go down
View user profile
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic OOP in Python   Sat Oct 23, 2010 12:35 pm

*shakes head* Actors... highly strung... Laughing
Back to top Go down
View user profile
Excimer Sun Software

avatar

Posts : 152
Join date : 2010-05-07
Age : 25
Location : USA

PostSubject: Re: Basic OOP in Python   Sun Oct 24, 2010 10:03 pm

Indeed...*Tilk-face*
Back to top Go down
View user profile
The Fellow
Admin
avatar

Posts : 100
Join date : 2010-04-28
Age : 26
Location : In my head, dreaming up how to shake up the world

PostSubject: 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.
Back to top Go down
View user profile http://compilecrazy.forumotion.net
Compu-Teck Inc.



Posts : 80
Join date : 2010-04-29
Age : 25

PostSubject: Re: Basic OOP in Python   Tue Oct 26, 2010 8:38 am

Eh, I think the "Basic OOP in Python" is done as far as relevancy goes... Rolling Eyes Rolling Eyes Rolling Eyes
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Basic OOP in Python   

Back to top Go down
 
Basic OOP in Python
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Compile Crazy :: Programming :: Python :: Advanced Topics-
Jump to: