Python supports various operations and manipulations on its built-in data types:
- Arithmetic operations (addition, subtraction, multiplication, division, modulus, exponentiation) for numerical data types (integers, floats).
# Arithmetic operations for numerical data types (integers, floats)
a = 10
b = 3
# Addition
addition_result = a + b
print("Addition:", addition_result)
# Subtraction
subtraction_result = a - b
print("Subtraction:", subtraction_result)
# Multiplication
multiplication_result = a * b
print("Multiplication:", multiplication_result)
# Division
division_result = a / b
print("Division:", division_result)
# Modulus
modulus_result = a % b
print("Modulus:", modulus_result)
# Exponentiation
exponentiation_result = a ** b
print("Exponentiation:", exponentiation_result)
- String concatenation (+) and repetition (*) for string manipulation.
# String concatenation (+) and repetition (*) for string manipulation
string1 = "Hello"
string2 = "World"
# Concatenation
concatenated_string = string1 + " " + string2
print("Concatenated String:", concatenated_string)
# Repetition
repeated_string = string1 * 3
print("Repeated String:", repeated_string)
- Comparison operators (==, !=, <, <=, >, >=) for comparing values and producing boolean results.
# Comparison operators (==, !=, <, <=, >, >=) for comparing values and producing boolean results
x = 10
y = 20
# Equality
print("Equality:", x == y)
# Inequality
print("Inequality:", x != y)
# Less than
print("Less than:", x < y)
# Less than or equal to
print("Less than or equal to:", x <= y)
# Greater than
print("Greater than:", x > y)
# Greater than or equal to
print("Greater than or equal to:", x >= y)
- Logical operators (and, or, not) for combining boolean expressions.
# Logical operators (and, or, not) for combining boolean expressions
p = True
q = False
# Logical AND
print("Logical AND:", p and q)
# Logical OR
print("Logical OR:", p or q)
# Logical NOT
print("Logical NOT:", not p)