1. Variables in Python
A variable is a name that refers to a value.
`name = "Python"
age = 25
print(name)
print(age)
Output:
Python
25`
Python automatically determines the type of a value when it is assigned to a variable.
2. Operators in Python
Operators are symbols or keywords that perform operations on values.
*Arithmetic operators
*
`a = 10
b = 3
print(a + b) # Addition
print(a - b) # Subtraction
print(a * b) # Multiplication
print(a / b) # Division
print(a % b) # Modulus
Output:
13
7
30
3.3333333333333335
1`
Comparison operators
Comparison operators compare two values and return True or False.
`print(10 > 5)
print(10 == 5)
print(10 != 5)
Output:
True
False
True`
3. Type Conversion
Type conversion means converting a value from one data type to another.
`age = "25"
age = int(age)
print(age)
print(type(age))
Output:
25
Here, int() converts the string "25" into the integer 25.
- Taking Input from the User
Python provides the input() function to accept information from a user.
name = input("Enter your name: ")
print("Hello", name)
The program asks for a name and displays a greeting.
Top comments (0)