Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Currency Converter

Wow. Yes that code could be improved, a lot. def means declare function. Simply put, it basically creates a variable that, when called, will execute instructions.

PHP Code

<?php 
def hi
():  #Creates a function under the name "hi"
  
print "Hello World"  #This is where the body of the functin is (the instructions executed)
hi()  #This is the function call, and when this is called, all the instructions within the function body will be executed successively 

The body of the function is not executed until the function is called.

You can read more about functions here:
http://docs.python.org/release/1.5.1p1/t...tions.html
and here:
http://www.tutorialspoint.com/python/pyt...ctions.htm
(Nov 10, 2013 11:30 AM)XBatt Wrote:  Ah, that's quite easy to understand. And how can I improve the code?

Also, when writing out the body of the def how do you tell python this is the end of the body of def?

The body of the function is indented. Once indentation ceases, the interpreter assumes that that is the end of the function declaration.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by MymannNov 8, 2017 12:11 PM 5 302 Nov 8, 2017 12:11 PM
Last Post: ahemokay
[.NET] by N1nj4Styl3Sep 5, 2015 12:50 AM 9 617 Sep 5, 2015 12:50 AM
Last Post: Odus
[Python] by XBattFeb 4, 2014 01:07 PM 7 172 Feb 4, 2014 01:07 PM
Last Post: Tony S