Variables are things you can store data in. For example, if I want the computer to remember the number
5, I can assign it to a variable as data. You do that by coming up with a variable name (let’s call our variable
x) and saying
x = 5.
Now when you say
xin your code, the computer will remember you saved
x, and recall it. Here are some examples and their corresponding type name in Python:
x = 5→ integer (int)
a = 9.2→ floating point number (float)
hey = 'hello'→ string (str)
ohmygod = ' random string'→ string (str)
green = True→ boolean (bool)
# use variables to store data first_name = "Jane" last_name = 'Doe' age = 25 price = 16.54 is_raining = True can_vote = False # variables can be assigned different values print(first_name) # prints Jane first_name = "John" print(first_name) # prints John
View code on GitHub.
Set a variable named
"Hi it's a good day"and a variable named
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact email@example.com for inquiries.