In this tutorial, we will learn about Python variables and data types being used in Python.
What are Python Variables?
- Python variable do not need explicit declaration to reserve memory space
- The declaration happens automatically when you assign a value to variable.
- The equal sign (=) is used to assign value to variable.
Let’s see some example of creating variables in python.
counter = 10 #an integer assignment
mile = 10.05 #a floating point
name = "Chepi" #a string.
Multiple Variable Assignment
Python allows you to assign a single value to several variables simultaneously.
a = b = c = 100 #same value assign to all the variable;
a = 7; b = 10 ; c = "Chepi"; #different value assign to different variable with single line
a, b, c =7, 10, "Chepi" #different value assign to different variable with single line
Please read related topic for more understanding on Python
Python Introduction
Python Get Started
Python Basic Syntax
Keywords and Identifiers
Rules for Python Variable name
- A variable name can not start with a number
- There can be no spaces in the name, use _ instead of space.
- Can’t use any of these symbols:'”,<>/}]()!@#$%^&*-~
- It is considered best practice (PEP8) which means are lowercase.
- Avoid using keywords in variable names.
What are Data Types available in Python?
Python has many type of data types. Let’s see the below details.
String – It contains text type data.
Numeric Type – It has different type of data such as Integer, Floating Point and Complex.
Sequence Type – It has different type data contains in sequence order such as list, tuple
Mapping Type – This type data type contains key pair value such as dictionary
Boolean Type – It can contains bool value