Python Variable Data Types
Python have different data types:
Assigning Values to Variables
x = 3 # Float y = "StudyGyaan" # String z = 2.15 # Float print(x) print(y) print(z)
Variables do not need to be declared with any particular data type and can even change type after they have been declared and stored.
x = 5 x = "StudyGyaan" print(x)
In python, variable values can be assigned multiple time
x = y = z = 786
Rules for Initialising Variables or Identifiers in Python
A python identifier starts with A to Z or a to z or an underscore( _ ) followed by zero or more letters, underscores, and digits (0 to 9).
Allowed Identifiers: A, a, _a, _A123, _123, etc.
Not Allowed Identifiers: 123, $ads, etc.
Python variables are basically output using the print statement. We can use + symbol to concate two strings and add two number variables in Python.
x = "awesome" # String print("Python is " + x) # Output: Python is awesome x = 5.5 # Float y = 10 # Integer print(x + y) # Output: 15.5
If you try to combine string and number, it will throw an error:
x = "Beginners Guide" y = 10 print(x + y) #Output: TypeError: unsupported operand type(s) # for +: 'int' and 'str'
Whats Next – Python Strings