I want to print text to tell what the numbers mean when l run the code. As the code is now it only show the numbers, l want it to have cities 200, people 500000
Code:
cities = 200
people = 500000
print(cities,people)
I want to print text to tell what the numbers mean when l run the code. As the code is now it only show the numbers, l want it to have cities 200, people 500000
Code:
cities = 200
people = 500000
print(cities,people)
Try this:
cities = 200
people = 500000
# (1)
print("cities %d ,people %d" % (cities, people))
# (2)
print("cities {} ,people {}".format(cities, people))
# (3)
print("cities {num1} ,people {num2}".format(num1=cities, num2=people))
# (4)
print("cities", cities, ",people", people)
# (5)
print("cities " + str(cities) + " ,people " + str(people))
# (6)
print(f"cities {cities} ,people {people}")
Output:
cities 200 ,people 500000
fstring
:cities = 200
people = 500000
print(f"cities {cities},people {people}")
cities 200,people 500000