Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

310 bytes added, 08:10, 31 May 2017
PART 1 - Using Functions
:'''Perform the Following Steps:'''
:#Let's experiment with defining and running functions.To start, open ipython and try experimenting with functions.the ipython3 shell:<source>
ipython3
</source>:#Whenever you want to create a function, you must start with the keyword "'''def'''". The '''def''' keyword is used to start the definition of the function, it does not run the code you write. Functions, just like if statements, must have all code under them indented.<br><br>:# Enter the following code in your ipython3 shell:<source>
def hello():
print('Hello World')
print('Inside a Function')
</source>:#You should notice that nothing happened. Well actually, something did happen... the function called '''hello(''') has been defined and stored in internal memory in order for it to run when called by its function name. Now that our function was created, we can use it over and over. <br><br>:#To execute the code inside the function, run the function name with "'''()'''" '''brackets''' at the end of the function name.<br>Try running the '''hello()''' function by name three times by issuing the following:<source>
hello()
hello()
13,420
edits