Sign in

Intro to Computer Science / Unit 4: Programming Basics in Python

4.1 Output and Variables

3 practice questionsNot yet reviewed

Notes

The print() function displays output. A variable is a name that stores a value. You create one with the assignment operator =.

  • Variable names use letters, digits and underscores, cannot start with a digit, and are case sensitive (score and Score are different).
  • Assignment copies the value on the right into the name on the left. A variable can be changed later.
  • # starts a comment, which Python ignores.
name = "Mia"
points = 10
points = points + 5
print(name, points)
  • This prints Mia 15. First points is 10, then it is reassigned to 10 + 5.

Practice

What does x = 4; x = x + 3; print(x) print?
Which is a valid Python variable name?
What does a = 5; b = a; a = 9; print(b) print?

Ready for more? Take the Unit 4 test.