variables in python

Variables In Python

Spread the love

Variables are used to store values in the memory of a computer. a variable name is a name that given to the memory block of the computer to store the value which we assign to the variable. Why use variables in python?

Why use variables?

  • When you are writing a long program and need to use a value often and which is long, then you can use a short variable name instead of a long value.
  • When you take input from the user you need to save it somewhere for later use in the program.

To declare Variables In Python, you have to first give a name to it and also you have to declare some values. Later, whenever we use that variable name in our code it will use that variable value in the place of the variable name while executing. so, basically, they store the values to access later.

Defining a Variables In Python
  • Syntax to define a variable

Variable name =  variable value

Variables In Python
  • You can change the value of a variable any time. When you assign a new value to the variable it will modify the value in the computer memory and it will use this new value in the future. Have a look at this example.
  •  Example,
Variables In Python
  • You can assign values to multiple variables at once 

  For Example,

defining variables
Rules to define a variable name
  • Can only contain  alpha-numeric characters and underscore (A-z, 0-9, _ )
  • Starts with any letter or an underscore character(_)
  • Doesn’t start with a number
  • A variable name is case-sensitive in python.
  • Can’t use reserved key-words

In python, unlike some other languages, you don’t have to declare the variable type. It will automatically do it on the basis of the value you assign to it.

BONUS

To know which keywords are reserved python, just execute this following command

keywords In Python

Blog you may like : Comment In Python

If you have any questions you can Message me on Instagram


Spread the love
2 comments
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Loops In Python

Spread the love

Spread the love There are 2 type of loops in python. for loop while loop Let’s have detailed information about loops in python. For loops in Python for loops in…
Spread the love
View Post

Function in Python 3

Spread the love

Spread the love As you all know there are many built-in function is python 3. Like, range(), print(), map(), eval() and many more. Function in python is made for do…
Spread the love
View Post

Comments In Python

Spread the love

Spread the love In programming, comments are the readable texts in the source code which are completely ignored by compiler or interpreter. It helps the programmer to remember what tricky…
Spread the love
View Post