A variable is a name that stores a value.
age = 36
This line creates a variable named age and stores the value 36 in it. The = sign assigns the value on the right to the name on the left.
Once a variable exists, its name stands for its value:
age = 36
next_year = age + 1
next_year now holds 37.
Variable names are lowercase. Words are separated by underscores: first_name, items_sold. A name cannot contain spaces and cannot start with a digit.
Text values are written between quotes and are called strings: "Melbourne". Numbers are written without quotes: 5400000. A number in quotes is a string, not a number.
Create three variables:
city — the string "Melbourne"population — the number 5400000country — the string "Australia"Then print the three variables.
Press Submit to check your work.
import unittest
class TestVariables(unittest.TestCase):
def test_city_is_the_string(self):
self.assertEqual(city, "Melbourne")
def test_population_is_the_number(self):
self.assertEqual(population, 5400000)
def test_country_is_the_string(self):
self.assertEqual(country, "Australia")
city = "Melbourne" population = 5400000 country = "Australia"
Sign in to join the discussion.
No comments yet. Be the first to ask a question.
Press Run to execute your code, or Submit to test and complete this problem.