Module 2, 2.1.3 Python Operators

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Hierarchy of Priorities

Causes some operators to act before others. It assumes that operators of a larger (higher) priority perform their operations before the operators of a lower priority.

Expressions

Comprised of data and operators.

The // operator.

integer division (floor division)

Right-sided binding operator

Evaluate the expression, print(2 ** 2 ** 3) from right to left: 2 ** 3 gives 8, and then 2 ** 8 gives 256.

Left-sided binding operator

Evaluate the expression, print(9 % 6 % 2) from left to right: first 9 % 6 gives 3, and then 3 % 2 gives 1.

T/F The code print(2.**3) will result in an 8 being displayed in the output.

False

T/F The code print(6 / 3) will result in an integer.

False

T/F The code print(6. // 4) will result in a 1 being displayed in the output.

False

The * operator.

multiplication

urary

Operator with one operand.

Binary

Operator with two operands.

floor division

The operation that divides two numbers and rounds to the lesser integer.

T/F The code print(2**3) will result in an 8 being displayed in the output.

True

T/F The code print(6 / 3) will result in a float.

True

T/F The code print(6 // 4) will result in a 1 being displayed in the output.

True

T/F The code print(9 % 6 % 2) will result in a 1 being displayed in the output.

True

T/F The default result of the / division operator is always a float.

True

The / operator.

division

Operator examples

+, -, *, /, //, %, **

Operators defined

A python symbol that is able to operate on values.

Evaluate print(2 * 3 % 5)

Answer: 1

Evaluate print((5 * ((25 % 13) + 100) / (2 * 13)) // 2)

Answer: 10.0

Parentheses

Used as grouping symbols for operations. The operations within the parentheses are performed first.

integer vs float rule

When at least one argument is a float, the result is a float. When both arguments are integers the result is an integer. Except when / is the operator.

The ** operator.

exponentiation

%

remainder(modulo), does division and returns the remainder


Kaugnay na mga set ng pag-aaral

Combo with "Patient Management: Dental Boards Mastery II" and 6 others

View Set

#1: Information and Communication Technology

View Set

Turning Points of the Revolution

View Set