EXPRESSIONS
EXPRESSIONS IN PYTHON
In Python, expressions are combinations of values, variables, operators, and function calls that produce a result. Here are some examples of expressions in Python
Arithmetic Expressions:
- Addition:
2 + 3
- Subtraction:
5 - 2
- Multiplication:
4 * 6
- Division:
10 / 2
- Modulo (remainder):
15 % 7
- Exponentiation:
2 ** 4
- Equality:
3 == 3
- Inequality:
4 != 6
- Greater than:
5 > 2
- Less than:
8 < 10
- Greater than or equal to:
7 >= 5
- Less than or equal to:
9 <= 12
- Logical AND:
True and False
- Logical OR:
True or False
- Logical NOT:
not True
String Concatenation:
greeting = "Hello" + " " + "World"
Function Calls:
len("Hello")
# Returns the length of the string "Hello"max(3, 9, 2)
# Returns the maximum value among the given arguments
x = 10
- y = x + 5
These are just a few examples of expressions in Python. Expressions can be as simple as a single value or more complex with multiple operators and function calls. They are used to perform calculations, make comparisons, manipulate strings, and more in Python programs
Comments
Post a Comment