Python Variables
- Python doesn’t have a specific “keyword” for variables.
- No need to specify the type of data for given variable.
- You can change the value of that variable in the same programming file even further.
Data Types:
Variable Type | Declaration |
---|---|
Integer | x=5 |
Float | f=0.1 |
String | s=”zeroones” |
Boolean | b=True |
Example:
simple value assign to various data type.
x = 5 #interger y = 0.5 #float b = True #Boolean s = "John" #string
Variables name are case sestivite and you can write string in single quotes and double quotes as well.
But in the python data type casting concept available. If you want to convert one data type to another data type then go for type conversion.
x = 25 y = '3' z = "54" print(type(x)) # output int print(type(y)) # output string print(type(z)) # output string x1 = str(x) # x interger to string y1 = int(y) # y char to interger z1 = float(z) # z string to float print(x1) print(y1) print(z1) print(type(x1)) # output string print(type(y1)) # output integer print(type(z1)) # output float
Function “type()”: This Function return the type of variable, as you saw in the previous example.