Variables
The memory location known as variables is where data is stored.
It can hold a value like a container and change its value during execution.
When assigning a value to a variable, we use the assignment operator (=).
Types Of Variable
- String
- Float
- Long Integer
- Integer
🔹 1. String (str)
A string is used to store text or characters.
Strings are written inside quotes (' ' or " ").
Example:
name = "Python"
city = 'Delhi'
print(name)
print(city)
🔹 2. Integer (int)
An integer stores whole numbers (no decimal point).
Example:
age = 20
marks = 95
print(age)
print(marks)
🔹 3. Float (float)
A float stores decimal numbers.
Example:
price = 99.50
temperature = 36.6
print(price)
print(temperature)
🔹 4. Long Integer
In Python 3, there is no separate long integer type.
int itself handles long (very large) numbers.
Example:
big_number = 12345678901234567890
print(big_number)
Program:
x = 10
print(type(x))
Python Programming Language:
In contrast to other programming languages, Python does not require you
to specify the type of value it holds nor does it have a command to create
a variable. When a value is first assigned to a variable, it is
created.
(Ex):
Here, input is the variable name.
- The assignment operator's name is =.
- It has been given the value of 10.
Rules To Declare A Variable:
- Every variable name begins with an underscore or alphabet.
- Numeric names should not be used to begin variables.
- The name of a variable can only contain underscore (_) and alphanumeric characters (A-Z, a-z, 0-9).
- The names of variables are case-sensitive.
Right Way To Declare A Variable:
- Beginning with underscores is permitted (first variable=10). Beginning with underscores is permitted.
Ways Not To❌ Follow To Declare A Variable:
- (first variable=10), the space between the words.
- Beginning with the number - (78th variable = 10)
- (first-variable=10, first+variable=10) Special characters are not permitted.
- Beginning with the number - (third-firstvariable = 10)
More topic in Python