1.1+Hello+Universe+py

Now that we have set up python, we now need to make some code! Make sure to run all of the examples so you know what output you get and how all the code works, and dont JUST run examples, make your own code and run it as well! Its the only way you will truly understand the language! The first piece of code we will be running will be a simple one, all it has to do it print out hello world, and python's hello world is one of the shortest! Unfortunately, i think hello world is a little overused, so instead of it, ill use hello universe!

code format="python" >>>print "Hello Universe!" Hello Universe! code As you can see, its a very simple code, and luckily, needs a simple explanation :). 'print' is a keyword of the python language, which outputs whatever is after it onscreen! "Hello Universe!" is a string, shown by the " ", in python, you may use either single or double quotes to create a string, but whatever the string is started with, it must also end with for example code format="python" print 'Hello Universe!'
 * 1) will work

print "Hello Universe!' print 'Hello Universe!" code You may be a little confused by the #'s in this peice of code, they are comment markers, the interpretor completely skips anything on a line after a #, so they are used to explain pieces of code, i will be using them throughout the tutorial to show how different things work. Now, thats all nice and simple, one keyword so far isnt too bad, but you may ask "saying hi to the universe is all well and good, but what if my friends want a hello too!?" lets learn a bit more!
 * or
 * 1) will not work

Variables, any programming language you will ever use has them, and lets explain a bit now. A variable is a like a container in your computer which holds a value in it. The container has been given name and a value one way or another, and we can do nearly anything we want with this variable (different variable types can be changed in different ways). e.g. A variable named x could correspond to the integer 1 or the string "Hello", and then we could use this variable any way we could use the number or the string! for example: code format="python" >>>x = "hello" >>>print x hello >>>b = 10 >>>c = 20 >>>print b*c 200 code In this example, first, we assign the string "hello" to the **value** of x, then we print the **value** in x, which would be the same as printing "hello", but by using x, there are many new things we can replace that regular string with! In the second part of the example, we see some basic math using the *(multiplication) operator, we see that b = 10 and c = 20, so b * c = 10*20, which is 200! Yay! Python is smart isnt it!

Now to introduce your first function One useful function is raw_input, a useful command to a veteran or beginner! This gets a value from the user, and returns it as a string. for example code format="python" name = raw_input code 'raw_input' will get the value the user types in, and assign that as a string, to the variable 'name' Now that we can get input, lets get the user's name! code name = raw_input print "hello",name code This code will take in the users name as a string, then assign it to the variable name like in the last example, but the print statement looks a little different doesnt it? Lets have a look at some of the different things the print statement does in our example! As you see in the example, the string "hello" is followed by a comma, then the variable 'name', the comma means 'put a space here', so its saying to the computer print hello, then a space, then name on one line!

'raw_input' also takes an argument, an argument is an item that you can put between the brackets of functions. 'raw_input' takes one argument, a string to print before you input your text, for example code format="python" >>>name = raw_input('Enter your name: ') Enter Your Name: Kye >>> print name Kye code Prev Next