Python Function Tutorials

in #python7 years ago

Python functions.

So lets assume you know how print works.
For example,
print ("Hello world")
OUTPUT
Hello world


First to use functions you need to define a function.
This can be done like this
def
def stand for define. After you define the name of the function it must be followed by a :
for example,
def functionname:

In my situation i'm going to define the function name to helloworld.
Example:
def helloworld:

CONGRATULATIONS, you defined the function however, you're not done yet. You need to add code to the function. Because I want it to output "Hello world" when it is called on I will add it.
Example:
def helloworld:
print("Hello world")

OUTPUT:
(Nothing)

As you can see this code outputs nothing, this is because you have not called on the function to do this you must write
functionname() on your code where you want it to appear.
Example:
def helloword:
print("Hello world")
helloworld()

OUTPUT:
Hello world

Thanks for reading. If this helped you please follow and upvote to help other users! If you require further assistance or help with more complicated code, tell me in the comments below and i'll try my best.

Sort:  

Want to implement your first AI? Check out our post :)

Congratulations @fataldeadboy! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got your First payout

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @fataldeadboy! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @fataldeadboy! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!