Docsity

Data Science: Python Assignment Operators, Lecture notes of English

Partial preview of the text

Download Data Science: Python Assignment Operators and more Lecture notes English in PDF only on Docsity!

Data Science: Python Assignment Operators

•^

Assign

values

to^

variables

Data Science: Python Assignment Operators^ Operator Name+

Addition

‐^

Subtraction

*^

Multiplication

/^

Division

%^

Modulus

**^

Exponentiation

//^

Floor

division

But

first…..let’s

review

the

arithmetic

operators

Data Science: Python Assignment Operators

Operator Name

Example Same

As^ Outcome

=^

Assign

x^ =^8

X^ =^8

8

+=^

Add^ and

Assign

x^ +=^8

x^ =^ x^ +

8

16

‐=^

Subtract

and^ Assign

x ‐=^8

x^ =^ x^ ‐^

8

0

*=^

Multiply

and^ Assign

x *=^8

x^ =^ x^ *

8

64

/=^

Divide

and^ assign

x^ /=^8

x^ =^ x^ / 8

1

%=^

Mod^ and

Assign

x^ %=^8

x^ = x^ %^8

0

//=^

Floor^ Divide

and^ Assign x

//=^8

x^ =^ x^ //

8

1

**=^

Exponent

and^ Assign

x^ **=

8 x^ =^ x^ **^

8 16777216

If^

Does

not

make

sense,

then

don’t

worry

about

it!

Just

remember…..

Plus

the

=^ operator

Data Science: Python Assignment Operators

Data Science: Python Relational Operators^ Operator Name

Example

==^

Equal

x^ ==

y

!=^

Not

equal

x^ !=

y

^

Greater

than

x^ >^ y

<^

Less

than

x^ <^ y

=^

Greater

than

or^ equal

to x

=^

y

<=^

Less

than

or^ equal

to^

x^ <=

y

Data Science: Python Relational Operators

Data Science: Python Membership Operators Operator Description

Example

in^

Returns

True

if^ a

sequence

with

the

specified

value

is^ present

in^ the

object

x^ in y

not in^

Returns

True

if^ a

sequence

with

the

specified

value

is^ not

present

in^ the

object

x

not

in^ y

Data Science: Python Membership Operators Operator Description

Example

in^

Returns

True

if^ a

sequence

with

the

specified

value

is^ present

in^ the

object

x^ in y

not in^

Returns

True

if^ a

sequence

with

the

specified

value

is^ not

present

in^ the

object

x

not

in^ y

Data Science: Python Logical Operators^ Operator Description

Example

and

Returns

True

if^ both

statements

are

true

x^ >^2

and

x^ <

or^

Returns

True

if^ one

of^ the

statements

is^ true

x^ >^2

or^ x

<^8

not

Reverse

the

result,

returns

False

if^ the

result

is^ true

not(x

^ 2and

x^ <

Data Science: Python Logical Operators

Data Science: Python Conditional Statements (if statement)^ If^

condition:x^ =

x^ +

y^ =^

y^ +

In^ English:If^ this

is^ true

then

do

{^ x^

=^ x^

+^1

y^ =

x^ +

In^ English:If^ this

is^ false

then

do

{^ x^

=^ x^

+^1

y^ =^

x^ +^

Or

In^ Python:

Data Science: Python Conditional Statements

Data Science: Python Conditional Statements

Data Science: Python Conditional Statements

(if …elif….statement)

if^ condition:x =^ x

+^1

y^ =^ y^ +^

elif:print

(“error”) print

(“good

bye”)

In^ English:If^ this

is^ true

then

do

{^ x^ =

x^ +

y^ =^ x^ +^

} Else

if^ this

is^ true {^ print

a^ message print

good

bye

}

In^ English:If^ this

is^ false

then

do

{^ x^ =

x^ +

y^ =^

x^ +^

} Else

if^ this

is^ false {^ print

a^ message print

good

bye

}

Or

In^ Python: