Page 42 - Code & Click - 7
P. 42
String Operators
String operators are used to perform operations on string values.
Operator Name Description Example Output
Concatenates or joins two “Amit” +
+ Concatenation “AmitGupta”
string values into one string. “Gupta”
Repeats the specified string a
* Replication “A”*3 A A A
specified number of times .
Experiential Learning
Lab Activity 6
Program to illustrate the use of Concatenation and Replication operator.
1. Type the code as shown in the image in the Python Editor.
2. Press the F5 key to execute the code. Sample output of the program is given.
PRECEDENCE OF OPERATORS
An expression in Python can comprise multiple operators and operands. To evaluate such expressions
correctly, it is important to know which operator will be evaluated earlier and which will be evaluated
later. This is called the Rule of Precedence. A higher-level precedence operator is evaluated before
an operator of lower-level precedence. In case, operators have the same precedence level, they are
evaluated from left to right in the expression.
The table given below gives the precedence of operators, from highest to lowest, in Python.
Description Operator
Parentheses ()
Exponentiation **
Multiplication, Division, Floor division, Modulus *, /, //, %
Addition, Subtraction +, –
Relational operators >, <, >=, <=, ==, !=
Logical operators and, or, not
Knowledge Discovery Subject Enrichment
The order of precedence of arithmetic operators follows the mathematical rule of BEDMAS. BEDMAS stands
for Brackets, Exponentiation, Division, Multiplication, Addition, and Subtraction.
40