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

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

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
Image of page 1

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

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
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.
  • Summer '17

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern