HomePortalFAQSearchMemberlistUsergroupsRegisterLog in

Share
 

 Basic OOP in Python

Go down 
AuthorMessage
Compu-Teck Inc.



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

Basic OOP in Python Empty
PostSubject: Basic OOP in Python   Basic OOP in Python I_icon_minitimeMon 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

Excimer Sun Software

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

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeSat 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 : 26

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

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

Excimer Sun Software

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

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeTue 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 : 26

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeTue 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

Excimer Sun Software

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

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeWed 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 : 26

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeThu 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

Excimer Sun Software

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

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeThu 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 : 26

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeThu 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

Excimer Sun Software

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

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeSat 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!!!!!!

Basic OOP in Python 1159046357_bluedragon
Back to top Go down
View user profile
Compu-Teck Inc.



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

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

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

Excimer Sun Software

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

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

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

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

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeSun 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 : 26

Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitimeTue 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




Basic OOP in Python Empty
PostSubject: Re: Basic OOP in Python   Basic OOP in Python I_icon_minitime

Back to top Go down
 
Basic OOP in Python
Back to top 
Page 1 of 1
 Similar topics
-
» Ten Basic Checkmates to Know
» Visual Basic Chess
» HashTable Calculate
» Lopez (new engine)
» Marking red and green (basic in tuning a ctg book)

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