Variable is used for store the data in python programming language. The value of variable can be changed, and variable reused many times.
Syntax of Create Variable in Python Programming
Python has no command for declaring a variable.
var1 = 5; name = "JOHN" print(var1) print(name)
In Python Programming language, variables do not need to be declared with any particular type.
Type casting in Python Programming
The type casting is one data types to another data types.
x = str(5) # x will be '5' as a string y = int(5) # y will be 5 as a integer z = float(5) # z will be 5.0 as a float
How to get the type of variable
You can get the data type of any variable using the type() function.
x = 8 y = "lapmos" print(type(x)) print(type(y))
Single or Double Quotes in string
String is declared either by using single quotes or double quotes.
x = "JAMES" # x is a string and valid x = 'JAMES' # valid # both are same
Case Sensitive in Python programming
In Python programming language, Variables names are case-sensitive.
x = 5 X = "JAMES" # x and X are the different variable
Rules of Declaration Variable in Python Programming
- A variable starts with the alphabets or underscore in python.
- A variable can not start with number and any digits in python.
- No white space allowed to declare the variable in python programming.
- No Special Characters Allowed except underscore.
- Variable are case-sensitive.
#Valid / Legal variable names var = "lapmos" var1 = "lapmos" var_ = "lapmos" _var = "lapmos" VAR = "lapmos"
Multiple Variables in one line.
Python allows you to assign values to multiple variables in one line:
a, b, c = "JOHN", "JAMES", "NICK" print(a) print(b) print(c)
One Value to Multiple Variable at the one line.
a = b = c = "JOHN" print(a) print(b) print(c)
Datatypes in Python Programming
The Data types specifies the type of data that the variable can store the value.
Python has six basic data types which are as follows:
Keywords Python Programming language
Keywords is reserved word in Python Programming language. Keywords can not use as a variable. Keyword in Python Programming language :
Operator is a symbol that tells the computer to perform the mathematical and logical operation in python programming. Operators are used in program to manipulate the data and variable.
In Python It is called a string which is inside single or double quotation marks. We can write multiline string inside three single or double quotation mark.