Variables in Python

10 Nov Variables in Python

Variables

A variable is a name that represents a value stored in the computer’s memory.Programs use variables to access and manipulate data that is stored in memory.For example, a program that calculates the sales tax on a purchase might use the variable name tax to represent that value in memory. And a program that calculates the distance between two cities might use the variable name distance to represent that value in memory.

Creating Variables with Assignment Statements

An assignment statement is used to create a variable and assign a value to it.
here is the syntax:
variable = expression
The equal sign (=) is known as the assignment operator.variable is the name of a variable and expression is a value, or any piece of code that results in a value.After execution value on the right side will be assigned to the variable on the left side.

IN: width = 10
IN: print(width)

OUT: 10


Note: Never enclose the variable name in quote marks

Warning! You cannot use a variable until you have assigned a value to it. An error will occur if you try to perform an operation on a variable, such as printing it, before it has been assigned a value.

Variable Naming Rules


1. Python’s keywords are not allowed as a variable name.
2. A variable name cannot contain spaces.
3. The first character must be one of the letters a through z, A through Z or an underscore character (_).
4. After the first character you may use the letters a through z or A through Z, the digits 0 through 9, or underscores.
5. Uppercase and lowercase characters are distinct. This means the variable name ItemsOrdered is not the same as itemsordered.
6. No special characters are allowed other than underscore(_).

No Comments

Post A Comment

Powered by themekiller.com anime4online.com animextoon.com apk4phone.com tengag.com moviekillers.com