| We hope you enjoy your visit. You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you are already a member please log in to your account to access all of our features: |
| Python Tutorial: def | |
|---|---|
| Tweet Topic Started: Dec 9 2009, 09:46 PM (1,044 Views) | |
| Sothh | Dec 9 2009, 09:46 PM Post #1 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
This is the second Python tutorial. It teaches the def function. You have probebly seen def in alot of Python programs. It is quite powerfull. I am now using Python 2.6.4. OK, lets get started. Open up your favorite Python text editer (no, I don't been NotePad) and enter the following:
"def" declares the keyword "Test", it is followed by "():". "print" tells Python to print "See how def works?". "return" tells Python to return a value, in this case nothing. You should already know how the rest of the code works. We ask for input, and then if input == 'Test' we call Test(). This is the important part. When we call Test() we are executing what we defined above. This is kind of like scripts in Game Maker. We define them, and then call them when needed. Now I will show you how to use arguments.
"def Test(argument1,argument2):" We define Test, and this time add arguments. "Test(10,1)" The "(10,1)" are the two arguments. Makes since, right? There is one more thing you need to know, that is returning values.
After we define Test() we set value to 10. "return value" This returns value, so that when we print Test() the value value will be printed. Now get out there, you "expert" and show your friends. Have fun! |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| « Previous Topic · Tutorials · Next Topic » |





![]](http://z1.ifrm.com/static/1/pip_r.png)



9:02 PM Jul 11