Changes

Jump to: navigation, search

OPS435 Python Lab 1

2 bytes added, 11:15, 6 September 2017
PART 1 - Common Introductory Python Functions
ls
</source>Our first python code we will write is going to call the print function. A function is code that has been defined in another location. Functions can take arguments, use these arguments in some way, and then usually return a result. The first function we will use is the "print()" functions, it's sole purpose is to output information to the screen.<br><br>
:#At the prompt, execut execute the following:<source>
print()
</source>You will notice that nothing happened when we ran this "print()" function. This is because we didn't pass any arguments to it, lets try again.<br><br>
:# Issue the following function:<br><source>
print('hello world')
</source>This time we should now see that the python function "print()" has outputted to the screen the words 'hello world'. In python a word or a bunch of characters like 'hello world' is called a 'string'. So what we did In the above isexample, passed a '''string''' was passed as a '''argument''' to the print '''function'''. These words are important for understanding and talking about different aspects of code.<br><br>
:# Note that there are similarities between the Python print() function and the Bash echo command, but Python is more picky than bash (which is a good thing). Try to run print without the brackets or without the quotes to see what happens.
<blockquote style="margin-left:35px;">{{Admon/tip|Reading errors|One of the things that makes a good programmer is debugging skills. The first and most important debugging technique is reading and understanding error messages. Try to understand what the errors are saying even if you think you already know what the problem is and already have some idea about how to fix it.}}</blockquote>
198
edits

Navigation menu