Python Variables

Just like water is filled in the bottle. Water is value and bottle is variable of that value.

Similarly, a python has also a variable that holds value. Example, a=50

Creating Variables

You had not to declare any command to create a variable.

You can create a variable by the “=” sign. Example, a=”john”, b=5 etc.

Example

You can change the type of variable as per your interest.

Example

Change Type of variable

Casting

You can specify the data type of variable with the help of casting.

This will produce the default data type which we have done in casting.

Example

The casting of data type

Get the type

We can get the type of variable with the help of the type() method.

Example

Get the type

Single or double quotes?

A string variable can be declared by either double-quote or single-quote.

Another programming language has no facility of this type. In C double and single quotes are different meaning.

Example

Python string

Case Sensitive

Python is case sensitive language.

You can’t use ‘a ‘ and ‘A’ as the same variable.  Both will give different output.

Example

Case sensitive

Multiple assignment

You can assign multiple variables to one value in python. In another programming language, it’s tough to call.

Example

a=b=c=10

print(a)
print(b)
print(c)
Output:
10
10
10

Summary:

• We have not to give any command to declare a variable in python.

Python variable has a facility of multiple variables at once.

• There is no difference in any single or double quote.

In short python has the ease and flexibility of declaring and creating variable in python.

See Also:

https://vipulkunwar503.code.blog/2021/06/13/python-syntax/

/https://vipulkunwar503.code.blog/2021/06/10/python-numbers/

Leave a comment