Python — Variables
Every programming language has a different way to declare its variable. Before we go, what are variables? Variables are used to store information to be referenced or manipulated in a computer program. Variables have various data types like integer, float, double, string, and many more. In the previous post, we have installed Python and PyCharm as our code editor. So, in this post, we will discuss variables in Python.
Rules when declaring variables
- Case sensitive
- Avoid using numbers to declaring variables. Example: not 3age but age3
- Not need semicolon (;) at the end of the statement.
- The existed variable can be re-assigned with a new value.
Creating Variable
Python has no specified command to define a new variable. Example:
You can re-assign existed variable with a new value. Example:
You can declare your variable to a specific data type with casting.
If you want to get your variable type, use type() function. Example:
Data Types
Python provides some data types:
- Integer
- Float
- Complex Number
- String
- Boolean
to better understand, look at the following example.
Next post: