Python

How To Declare Variable In Python

In this post we will learn about variables in python , let’s get started

Variable are used to store data values.

If you haven’t Install Python Yet go and Install it  Install python .

In python there isn’t any command to declare a variable , The variable is declared the moment you assign value to it.

An example will help you to understand

a=5
b="Thecodehubs"
print(a)
print(b)

Output :

 

 

You don’t need to declare a variable with any particular datatype and you can change type by assigning a different datatype value

Lets take an example :

a=5 #a is type int 
a="Thecodehubs" # now a is type string
print(a)

Output:

 

You can declare string variable by using single or double quotes

a='Nisarg patel'
b="Thecodehubs"
print(a)
print(b)

Output : 

 

 

Rules to declare variable name

  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables

 

Assign value to multiple variables

a,b,c='Nisarg patel','thecodehubs',3
print(a)
print(b)
print(c)

output:

 

 

That’s all folks for today stay tuned for more blogs 🙂 

Checkout : List In python 

Nisarg Patel

Share
Published by
Nisarg Patel

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago