Recommendation from BiruniWeb:
Find news, information and updates about BiruniWeb at Biruni News.
Link: Biruni News
Variables are probably the simplest things in Python. Unlike JavaScript, you do not need to tell the computer, "Hey, this variable that I'm setting here is a new variable." It's as if in Python, the program has already created every possible variable, but gave it a value that the computer knows that if you have a variable with that value, the computer says that the variable doesn't exist.
To set a variable, write this:
My_variable = "String"
That is if you want it to be a string. A string can contain letters and numbers together, or it can be only letters.
For a number-only variable, write this:
My_variable = 1
For a Boolean statement, which is a value that is either true or false, write this:
My_variable = True or False
Lastly if you want your variable to have no value, you can't simply not write anything. You must write the following:
My_variable = None
Some rules for variable names are:
It cannot have punctuation in it, except underscores. No My_pet's_name
It cannot have spaces. No My pets name
It cannot start with a number. No 3_pets_names
You can redeclare a variable precisely the same way you declare it the first time.
My_variable = 2
That's variables in Python!