In this post we will learn about variables in python , let’s get started
Variable are used to store data values.
If you haven’t Install Python Yet go and Install it Install python .
In python there isn’t any command to declare a variable , The variable is declared the moment you assign value to it.
An example will help you to understand
a=5 b="Thecodehubs" print(a) print(b)
You don’t need to declare a variable with any particular datatype and you can change type by assigning a different datatype value
Lets take an example :
a=5 #a is type int a="Thecodehubs" # now a is type string print(a)
You can declare string variable by using single or double quotes
a='Nisarg patel' b="Thecodehubs" print(a) print(b)
Rules to declare variable name
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variable names are case-sensitive (age, Age and AGE are three different variables
Assign value to multiple variables
a,b,c='Nisarg patel','thecodehubs',3 print(a) print(b) print(c)
That’s all folks for today stay tuned for more blogs 🙂
Checkout : List In python