0% found this document useful (0 votes)
13 views5 pages

Assignment Opertators On Values

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Assignment Opertators On Values

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Understanding Boolean Values in Python:

A Boolean value is either True or False. Numerically, True is 1 and False is 0.

Step 1: New Terminal

Step 2: Open Python REPL

Step 3: RUN >>> name = ‘Edwin’ #Alpha

>>> name001 = ‘Edwin’ #AlphaNumeric

>>> _name = ‘Edwin’ #_Alpha

# SyntaxError:invalid syntax

>>> :name = ‘Edwin’

>>> 0001name = ‘Edwin’

>>> 1name = ‘Edwin’

>>> :name-first = ‘Edwin’

>>> name! = ‘Edwin’

#Reserved Keywords

>>> if = ‘Edwin’

>>> for = ‘Edwin’

1. Expression

>>> 2+2 #Numbers

>>> “Expression” #String

>>> myname = ‘Edwin’

>>> myname

‘Edwin’

>>>quit () #Save and Close (if required)

2. New File #Shortcut to Copy (shift+Alt+DownArrow)

>>> line01 = “*****************” # header /footer

>>> line02 = “* *” # re-use

>>> line03 = “**HELLO WORLD**” # File

>>> print(line01)

>>> print(line02)

>>> print(line03)

>>> print(line02)
>>> print(line01)

3. Assignment Operators
Step 1: Open New Terminal (Ctrl + ~)

Step 2: Open Python REPL (py)

>>> name = ‘Edwin’

>>> name

‘Edwin’

>>> Day = 100

>>> Day

100

#Arithmatic Calculator
>>> 4 + 4 #Addition

>>> 4 – 2 #Subtraction

>>> 4 * 4 #Multiplication

16

>>> 50 / 4 #Division

12.8

>>> 50 //4 #Round Division

12

>>> round(50 / 4) #Round Function

13

>>> 48 % 5 #Percentage

>>> 2 ** 3 #Exponents

>>> 2 ** 5

32

# Combining Assignment and Arithmetic Operators


>>> Day = 52
>>> Day += 1 #Addition

>>> Day

53

>>> Day -= 1 #Subtraction

>>> Day

52

>>> Day *= 10 #Multiplication

>>> Day

520

>>> Day /= 10

>>> Day

52.0 #Unexpected decimal value

>>> round(Day)

52

>>> Day

52.0

>>> Day = round(Day)

>>> Day

52

>>> “Edwin “ + “TS” #Concatenate two previous values

‘Edwin TS’

… Clear Terminal

# Comparison Operators (== is NOT an Assignment Operator) for Boolean Data


>>> 46 == 45

False

>>> 46 == 46

True

>>> 46 != 46

False

>>> 47 != 46

True
>>> 10 > 5

True

>>> 10 < 5

False

>>> 10 >= 10

True

>>> 10 <= 10

True

# Understanding Boolean Operators


>>> x = True

>>> y = False

>>> z = True

>>> not x # Boolean operator ‘not’ – is a Keyword gets the opposite


False

>>> not y

True

>>> not z

False

# ‘and’ looks both the value for True


>>> x and y

False

>>> y and x

False

# ‘or’ looks one or other is True


>>> x or y

True

>>> y or x

True

# Understanding ‘and’ & ‘or’ functions of Boolean


>>> x and z

True
>>> z and y

False

>>> y or z

True

>>> z or y

True

quit () ------- To close the terminal or quit the REPL

Ctlr + N --------- To open a new file

# Learn to script/code a short program


1 day = 52

2 print('')

4 if day > 10:

5 print('True')

6 else:

7 print('False')

Output: True
9 day = 9

10 print('')

11

12 if day > 10:

13 print('True')

14 else:

15 print('False')

Output: False
# To run it from the Terminal Window
>>> py day.py

# To highlight All the codes as # (HashTag) comments --------- Select the script + ctrl + /
# Ternary Operator
17 print('True') if day > 10 else print('False')

You might also like