Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

Discover Python and Patterns (7): Functions

$
0
0

It is now time to organize/refactor our code! When you begin, this is a strange process since the final code does the same as before. However, refactoring is the only way to create a code easy to maintain and expand.

This post is part of the Discover Python and Patterns series

Define a function

In the previous programs, we used existing functions like print() or input(). We can also create our own functions using the def statement:

   def printHello():
       print("Hello!")

The syntax is:

   def <function name>(<arguments>):<function body>

We can choose a function name as for variable …


Viewing all articles
Browse latest Browse all 17560

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>