VariablesTypesMath-1 - Variables, Data Types & Math...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1 with Robots Institute for Personal Robots in Education (IPRE)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aug 29 2007 2 Variables A variable is a name (identifier) that points to a value. They are useful to store values, and to refer to changing values by the same name. To create a variable, simply name it and assign it a value to point to with the assignment operator (single equal sign) >>> myName = “Jay” myName “Jay”
Background image of page 2
Aug 29 2007 3 Variables A variable name can be made up of letters, numbers, and the underscore ( _ ) character. The first character must be a letter. Variable names are case sensitive (myName and myname are different). >>> myname = “Scribbler” myName Jay myname Scribbler
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aug 29 2007 4 Variables >>> number1 = 3 >>> number2 = 2 >>> 3rdnumber = 5 Syntax Error: invalid syntax >>> import = 7 Syntax Error: invalid syntax number2 2 number1 3
Background image of page 4
Aug 29 2007 5 Using Variables When python sees a variable name, it evaluates the variable (sees what it points to) and uses the value that the variable points to instead of the variable name. >>> myName 'Jay' >>> number1 3 number1 3 myName “Jay”
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Aug 29 2007 6 Using Variables If the python interpreter finds an identifier or variable name that has not yet been defined, it will return an error. >>> aRandomName NameError: name 'aRandomName' is not defined number1 3 myName “Jay”
Background image of page 6
Aug 29 2007 7 Using Variables You can do math with variables that point to numbers. The python interpreter evaluates the variables by checking to see what number (value) they are pointing to, and then uses that value for the math. >>> 3 + 2 5 >>> number1 + number2 5 number1 3 number2 2
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Using Variables You can even store the answer in a new variable. >>> answer = number1 + number 2
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2012 for the course CS 1301 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 26

VariablesTypesMath-1 - Variables, Data Types & Math...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online