Python: Operators

Ace your homework & exams now with Quizwiz!

<

Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.

!=

Checks if the value of two operands are equal or not, if values are not equal then condition becomes true.

<>

Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true. This is similar to != operator.

==

Checks if the value of two operands are equal or not, if yes then condition becomes true.

:

Colons denote the beginning of a block of code, or the presence of an index between the objects on its left and right.

,

Commas separate parameters or arguments.

/=

Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a

/

Division - Divides left hand operand by right hand operand

**

Exponent - Performs exponential (power) calculation on operators

**=

Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a

//=

Floor Dividion and assigns a value, Performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a

//

Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. 9//2 is equal to 4 and 9.0//2.0 is equal to 4.0

=

Simple assignment operator, Assigns values from right side operands to left side operand c = a + b will assign value of a + b into c

<=

Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.

>=

Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.

>

Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.

.

A dot separates an object's name from the object's attribute being accessed or method being called. Note that some programmers refer to methods as attributes since they belong to an object. car.door='red' car.start()

+=

Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand. c += a is equivalent to c = c + a

+

Addition - Adds values on either side of the operator

%

Modulus - Divides left hand operand by right hand operand and returns remainder

%=

Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a

*

Multiplication - Multiplies values on either side of the operator

*=

Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a

;

Semicolons can separate different statements on a single line of code. a = b; d = b + 1; f = "cat"

-=

Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a

-

Subtraction - Subtracts right hand operand from left hand operand

@

This is known as decorator syntax. Decorators allow you to inject or modify code in functions or classes. @decoratorName def desiredFunction(): pass

{ }

Used to create a dictionary object.

[ ]

Used to create a list object.

( )

Used to define the parameters of a function, specify arguments passed to a function, or to specify the order of operations in a formula.


Related study sets

Chpts 4-7- Witches of Blackbird Pond

View Set

Internet Chapter 3-Searching The Web

View Set

Chapter 53: Assessment of Kidney and Urinary Function

View Set

The Peripheral Nervous System, Chapter 13

View Set

Physics 1408 Schaub Conceptual Questions

View Set

Derm Qbank: Surgical, Laser, Cosmetic

View Set

Ch. 9 emotion in relationships and society

View Set