Py-Tut-002

__**Back to Learning Python**__

Variables
From Algebra math class you learned about representing unknown or changing values with "x" or "y", etc. These are variables. In programs we use variables to represent items such as Integers, Real numbers, text strings, and more. In programming there is a common naming convention; all variables begin with lower case letters. Should you combine multiple words together, the subsequent words are capitalized. Examples include "myList", "counter", "tempVariable", and "x".

Declaring Variables
In most programming languages you need to tell the program about all variables before you can use them. This is not necessary in Python. However, it is still a good practise to indicate all variables at the top of your program so anyone else reading your program can understand it better.

Assigning Values
To assign a value to a variable, use the "=" operator. Integer values have no decimal. For Real (or floating) values, make sure to include a decimal in the assignment. Text strings need to begin and end with quotes. They can be either both single quotes or both double quotes.

x = 1 #this is an integer y = 1. #this is a real number (or floating number) question = "Is there someone else up there we can talk to?" # this is a text string response = 'No, now go away or I shall taunt you a second time.' # this is also a text string

Printing Multiple Items
Note that printing multiple items together will print them all on the same line. To separate items with a line feed, either include a carriage return directly with '\n' between items, or use separate print statements.

code format="python" print print question, answer print print question print response code



User Input
What if the value you want needs to be typed in by the user? This is where the "raw_input"

Assignment 2
Write a program that stores your name in one variable and your age in another variable. Print your name and age on the same line. Save it as "Py-tut-002.py"

__**Back to Learning Python**__