❮ Previous Next ❯

Python Variables and Inputs

We know that variable is a named memory allocation which assigns a value and which may vary at the time of execution.
Exa: myVariable=100
        If we call myVariable, then we will get 100



python-variable11.PNG

Python is case sensitive, that means there is a difference between uppercase and lowercase character.
For exa, if I will write MyVariable instead of myVariable, then it will give error.



python-variable12

We can perform mathematical operations using variable, like;
>>>myVariable+50
>>>150
>>>myVariable**2
>>>10000
The most important use of variable is to input a value. Exa;


python-variable13
Now if we will perform any mathematical operation using value, then we will get error
python-variable14

Because here value is a string. So to perform addition operation we have to cast in to int, which is known as typecasting. After type casting we can perform any mathematical operations.
>>> value=int(input("Enter the value"))
Enter the value200
>>> value
200
>>> value+50*6
500


Rules for Python variables:

How do I define a variable?

Defining a variable is a symbol, such as x, used to describe any number. When a variable is used in a function, we know that it is not just one constant number, but that it can represent many numbers.

Do you have to declare variables in Python?

There's no need to declare new variables in Python. If we're talking about variables in functions or modules, no declaration is needed. Just assign a value to a name where you need it: s= "Silan" . ... Variables have scope, so yes it is appropriate to have variables that are specific to your function.


❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved