Header Ads

Header ADS

Python Variables

Python Variables

Variable is a name that is used to refer to memory location. Variable also is known as an identifier and used to hold value.
A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Every value in Python has a datatype. Different data types in Python are Numbers, List, Tuple, Strings, Dictionary, etc


Variable Identifier :

> A variable name must start with a letter or the underscore character: Name, _Name
> A variable name cannot start with a number: 9name,5age
> 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)
> Identifier name must not contain any white-space, or special character (!, @, #, %, ^, &, *).
   
   Examples of valid identifiers : a123, _n, n_9, etc.
   Examples of invalid identifiers: 1a, n%4, n 9, etc

Assigning Values to Variables:

integer value assigning:
x = 77 print(x)
float value assigning:
y = 3.1416  print(y)
String value assigning:
string = "Hello World" print(string)
we can assign value to another type such as boolean, list, tuple, dictionaries, etc.

Multiple Assigning :

a = b = c = 1 print(a) print(b) print(c)
Output:
Output: 1 1 1

a,b,c = 1,2,"Akramul" print(a) print(b) print(c)
Output:
1 2 Akramul


No comments

Powered by Blogger.