In Python, a variable is a named memory where a programmer can store data and retrieve for future use using the same name. In Python, variables are created without specifying any data type. There is no specific keyword used to create a variable. Variables are created directly by specifying the variable name with a value.
We use the following syntax to create a variable.
Syntax
Variable_name = Value
When a variable is defined, we must create it with a value. If the value is not assigned the variable gives an error stating that variable is not defined.
Consider the following example Python code.
So when a variable has created, we must assign a value to it. Look at the following Python code.
Declaring multiple variables in a single statement
In Python, it is possible to define more than one variable using a single statement. When multiple variables are created using a single statement, the variables and their corresponding value must be separated with a comma symbol.
Let's look at the following code.
No comments:
Post a Comment