2-Basics - Python Basics 1 1 Variables A variable is a name...

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

View Full Document Right Arrow Icon
Python Basics 1 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Variables A variable is a name for a value Useful if we need to use that value again and again - we don't have to compute the value after the Frst time: give it a name, and just refer to it by name The value referred to by a name can change - that's why we call it a variable 2 2
Background image of page 2
Giving a value a name How do we give names to values? Use the = sign In Python, = does NOT mean "equals" my_grade = 99 We have given the name my_grade to the value 99 and we say that the variable my_grade refers to the value 99 3 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Defning a variable the frst time we use a name (variable) in a program by making it reFer to some value: age = 21 we say that we defne the variable 4 4
Background image of page 4
Form: variable = expression How it’s executed: 1. Evaluate the expression on the RHS. (The value of the expression is a memory address.) 2. Store that memory address in the variable on the LHS. Assignment Statement 5 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Form: variable = expression How it’s executed: 1. Evaluate the expression on the RHS. (The value of the expression is a memory address.) 2. Store that memory address in the variable on the LHS. Assignment Statement 6 Remember this! 6
Background image of page 6
Every Python value has a type that describes what sort of value it is Some types come with Python ( int, str ), others are made up by programmers ( Picture, Colorx ) Built-in function type will tell you the type of
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/26/2011 for the course CS a48 taught by Professor Michael during the Fall '10 term at University of Toronto.

Page1 / 21

2-Basics - Python Basics 1 1 Variables A variable is a name...

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

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