Changes

Jump to: navigation, search

OPS435 Python3 Lab 3

482 bytes added, 15:54, 19 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 way, that is OK. On the other hand, you may want to create and use a function to do something, like perform error checking or some other task that report back to the '''caller''' for further processing. For example, a '''true''' or '''false''' value if the error checking function that was called was detected no errors or detected 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 will return a special Python object called "'''None"'''. "'''None" ''' is a Python 3.x keyword which is used to indicate that there is "nothing". Let update the above Python script to the following version:<source lang="python">
def hello():
print('Hello World')
my_stuff = hello()
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 on implicitly.The following python script should produce that same result as the one above:<source lang="python">
def hello():
print('Hello World')
print('Inside a Function')
 
my_stuff = hello()
print('Stuff return from hello():',my_stuff)
print('the object my_stuff is of type:',type(my_stuff)
</source><br><br>
1,760
edits

Navigation menu