How to declare a variable in Python
Python is a dynamic-typed language, which means we don't need to mention the variable type or declare before using it. It makes to Python the most efficient and easy to use language. Every variable is treated as an object in Python.
Before declaring a variable, we must follow the given rules.
Let's understand the declaration of a few basic variables.
Python supports three types of numbers - integer, floating point numbers, and complex. We can declare a variable with any length, there is no restriction declares any length of the variable. Use the following syntax to declare the number type variables.
The type of a <class 'int'> 25 The type of b <class 'float'> 12.5 The type of c <class 'complex'> c is a complex number True
The string is the sequence of Unicode characters. It is declared using single quotes, double quotes, or triple quotes. Let's understand the following example.
JavaTpoint <class 'str'> JavaTpoint <class 'str'> This is string using the triple Quotes <class 'str'>
1. Assigning multiple values to multiple variables
We can assign the more than one variable simultaneously on the same line. For example -
Values are printed in the given order.
2. Assign a single value to the multiple variables
We can assign the single value to the multiple variables on the same line. Consider the following example.
JavaTpoint JavaTpoint JavaTpoint