{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

python04.html - CHAPTER 4 A variable is a labeled place in...

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

View Full Document Right Arrow Icon
CHAPTER 4 A variable is a labeled place in the computer memory that you can use to store a value in. this is an assignment: x = 5 in the assignment there is a left hand side and a right hand side after x = 5 is executed, the symbol x stands for its value print(x) prints the value of x variable = value remember a variable holds ONE value at a time x = 5 x = 2 print(x) Table Exercise: In the previous chapter you wrote a calculation that determines the number of seconds in a week. Copy this calculation into a program, and assign it to a variable. Then add a statement to print the contents of the variable. x = 5 print( x ) x = 7 * 9 + 13 # overwrite the previous value of x print( x ) x = "A nod is as good as a wink to a blind bat." print( x ) x = int( 15 / 4 ) - 27 print( x ) x = 2 y = 3 print( "x =", x ) print( "y =", y ) print( "x * y =", x * y ) print( "x + y =", x + y ) x = 2 print( x ) x = x + 3 print( x ) what does this print? quick! think about it, don't run the code print(x) x = 5
Background image of page 1

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

View Full Document Right Arrow Icon
A variable name must consist of only letters, digits, and/or underscores (_) A variable name must start with a letter or an underscore A variable name should not be a reserved word these are the reserved (31) words listed by Spronck: but there is a problem with this (see next slide) and del from not while as elif global or with assert else if
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}