Open main menu

CDOT Wiki β

Changes

OPS435 Python3 Lab 3

113 bytes added, 13:58, 25 September 2019
PART 1 - Function that does not take argument or return value
hello()
hello()
</source>You should notice that the function just does the same thing over-and-over no matter how many times your call the function by name. By the wayOn one hand, that is OK. On the other hand, you may want to create and use a function to do somethinguseful, like perform error checking or some other task that report something back to the '''caller''' for further processing. For example, return a '''true''' or '''false''' value if the by an error checking function that was called was detected no errors or detected to check where there is an error. But let's stick to some simple examples first, before tackling more complex use of functions. In Python, when a function does not return a value, it the Python interpreter will automatically return a special Python object called '''None'''. '''None''' is a Python 3.x keyword which is used to indicate that there is "nothing". 'None' is not the same as an empty object, like an empty string. Let update the above Python script to the following version:<source lang="python">
def hello():
print('Hello World')
print('Stuff return from hello():',my_stuff)
print('the object my_stuff is of type:',type(my_stuff))
</source>You can assume that there is a hidden '''return''' statement at the end of any function if it does not have one implicitly.The following python script should produce the same result as the one above:<source lang="python">
def hello():
print('Hello World')
1,760
edits