- Variables for strings
- Variables for numbers
Variables for Strings
- A variable is something that holds a value that may change.
- In simplest terms, a variable is just a box that you can put stuff in.
- You can use variables to store all kinds of stuff, but for now, we are just going to look at storing strings in variables.
name="Presidential Initiative for Al and Computing"
print(name)
- Creates a variable called name
- Assigns a string value “Presidential Initiative for Al and Computing” in this variable.
- Prints the string value stored inside this variable.
Variables for Numbers
a = 10
print(a)
Outputs: 10
a is variable name (identifier)
= is assignment operator
10 is value (integer value) storing in variable
Examples
To store floating point in variable
a = 5.3
To store string in variable
city = "Islamabad"
To store addition of two variable in another variable
num1 = 100
num2 = 200
sum = num1 + num2