Expressions
- An expression is a combination of values, variables,
and operators that produces a result.
- Example: 2 * (3 + 5)
Evaluation of an Expression
- Expressions are evaluated according to operator
precedence and associativity.
- Precedence:
The order in which operators are evaluated (e.g., multiplication before
addition).
- Associativity:
The order in which operators of the same precedence are evaluated (e.g.,
left-to-right or right-to-left).
Type Conversion
- Explicit Conversion (Type Casting):
- Manually converting a value from one data type to
another.
- Example: int(3.14)
(converts 3.14 to an integer)
- Implicit Conversion (Type Coercion):
- Automatic conversion of data types during an
operation.
- Example: 2 + 3.5
(integer 2 is implicitly converted to a float before addition)
Input/Output
- Input:
- input() function is used to get input from the user.
- Example: name = input("Enter your name: ")
- Output:
- print() function is used to display output to the console.
- Example: print("Hello, ", name)
No comments:
Post a Comment