CMPT 120 Lecture Notes - Lecture 9: Concatenation, String Operations, Order Of Operations

11 views2 pages
meghan78 and 39786 others unlocked
CMPT 120 Full Course Notes
29
CMPT 120 Full Course Notes
Verified Note
29 documents

Document Summary

Lecture 9 part 5: i/o functions, types, operator precedence, string operations. When an expression contains more than one operator, the order of evaluation depends on the order of operations. The acronym pemdas is a useful way to remember the rules: Parentheses have the highest precedence and can be used to force an expression to evaluate in the order you want. Expressions in parentheses are evaluated first, 2 * (3-1) is 4, and (1+1)**(5-2) is 8. You can also use parentheses to make an expression easier to read, even if it doesn"t change the result. Exponentiation has the next highest precedence, so: 1 + 2**3 is 9, not 27, and 2*3**2 is. Multiplication and division have higher precedence than addition and subtraction. 2*3-1 is 5, not 4, and 6+4/2 is 8, not 5. Operators with the same precedence are evaluated from left to right (except exponentiation).

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions