Python Variables – How to Create Python Variables

This is our second tutorial in Python, in this tutorial we are going to learn How to Create Variables in Python, also you can watch the complete video training for this article.

 

 

You can check  Python GUI Development Tutorials in the below link.

1: PyQt5 GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Pyside2 GUI Development Tutorials 

4: Kivy GUI Development Tutorials

 

 

 

 

Also you can watch the complete Video Tutorial for this article.

 

 

 

What are Variables ?

Variables are containers or placeholders for storing values. creating of variables are so easy in Python, you can just write the name and also the value of the variable. you don’t need to explicitly write the type of the variable. for example if your familiar with other programming languages like C++ or Java, when you write your variables, you need to specify the data type of the variables, but in Python you can just write the name and value of the variable.

 

 

 

OK now let’s create our variable like this.

 

You can see, that we have created variable at name of number and i have stored the 6 value in my number variable. now i can use this number and print that in the screen. also we have not explicitly specified the data type of the variable.

 

 

 

You can create variables for different data types, like string, float, text like this.

 

 

 

There are different rules for variable names.

 

1: When you are going to create variable, so the name should start with a letter, or underscore character.

So you can see in the code the first example is allowed, but the second example is not allowed.

 

 

2: You can not add space in variable name, but you can use underscore.

 

 

3: Don’t use Python built in keywords and functions as your variable name.

 

 

4: Variable names are case sensitive. name and Name are different variables.

 

Run this code and this will be the result.

 

 

 

 

 

 

 

 

 

 

Share via
Copy link
Powered by Social Snap