What is Python variable?
A Variables play a very important role in other Programming languages, and Python is no exception. A Variable allows you to store values by assigning it to a name, which can be used to refer to the value later in the program
Unlike other programming languages, Python has no command for declaring variables.
A variable is created the moment you first assign a value to it.
>>> x=3 # x is the type of Int >>> print(x) 3 >>> print(x+3) 6 >>> print(x) 3
The variable can be reassigned as many times as you want, in order to change their value.
In python, the variables don’t have specific types, so you can assign a string to variables, and later assign an integer to the same variables.
>>>x=45.23 # x is the type of Int >>> print(x) 45.23 >>> x="this is string" # x is the type of String >>> print (x) this is string >>>print(x + "!") this is string!
- To combine both text and a variable, Python uses the
>>> x = "awesome" >>> print("Python is " + x) Python is awesome