0% found this document useful (0 votes)
19 views4 pages

Model Notes Grade 9 - Python Basics

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

Model Notes Grade 9 - Python Basics

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

Python Basics

Introduction
1. Basic statement to print:
print(“Hello! World”)

Each individual part:


print
(

Hello
!
World

)

Are called as token.


2. Types of Tokens:
i. Keyword
ii. Identifier
iii. Literal
iv. Operator
v. Punctuator
3. Keyword: These are the special symbol and are reserved
words.

If, elif, else, print, for, while, range, int, input, float, while,
random, ………..
4. Identifier: The name given to any variable is called variable.
Rules:
a. Keyword cannot be used as identifier.
b. Identifier starts with alphabets and ‘_’(underscore) is
considered as an alphabet.
c. There is no space in identifier.
d. Identifier never starts with number.
5. Literal:
a. Integer
b. Float
c. None
d. Boolean
6. Punctuators: Special symbols in keyboard.
@,#,$,;
7.
Operators:

Operator Associativity Precedence


( ) Left to Right T
** Right to Left O
~ Left to Right P
+,- Left to Right
/ , * , // , % Left to Right T
+,- O
& Left to Right
^ B
| O
<,<=,>,>=,!=,== Left to Right T
Boolean NOT Left to Right T
Boolean AND Left to Right O
Boolean OR Left to Right M

8. Parenthesis – ( )

2+(3+5)*8 / 2
9. Exponent - **
P = 2**3
print(P)
OP: 8

Q = 2**2**3
print(Q)
OP: 256
10. 2’s Complement: ~
p=4
q = ~p
print(q)

OP: -5

a = 10001001
b = ~a

1’s Complement ( a ) = 01110110


2’s Complement ( a ) = +1
01110111
11. Floor Division - //
p = 9//4 #gives decimal truncated quotient
print(p)

OP: 2

Remainder - %
p= 9%4 #gives remainder
print(p)

OP: 1
12.
A B A AND (&) B A OR ( | ) B A EX-OR ( ^ )
B
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
13. Bitwise AND:
A = 1001010
B = 0011101
A AND B = 0001000
14. Bitwise OR:
A = 1001010
B = 0011101
A OR B = 1011111
15. Bitwise EXOR:
A = 1001010
B = 0011101
A EXOR B = 1010111
1. Basic Knowledge
A. Keywords:
i. Base: The number of symbols in a number system.
ii. Byte: 8 bits is knowing as 1 byte.
B. Short Notes:
i. Base: The number of symbols in a number system is called its
base. The number of symbols in decimal number system is 10
that is from 0 to 9. So, the base of decimal number system is
10. Similarly, the number of symbols in binary number system
is 2 that is 0 and 1. So, the base of binary number system is 2.
ii. 20 = 1; 21=2; 22=4; 23=8; 24=16; 25=32; 26=64; 27=128;
28=256; 29=512; 210=1024
iii. Convert Binary to Decimal:
a. (100011101)2
1 0 0 0 1 1 1 0 1
28=2 27=1 26=6 25=3 24=1 23= 22= 21= 20=
56 28 4 2 6 8 4 2 1
From Right Side:
1*256 + 0*128 + 0*64 + 0*32 + 1*16 + 1*8 + 1*4 + 0*2 +
1*1 = 285
1.3 Adding in binary
A. Rules:
i. 0+0=0
ii. 0+1=1
iii. 1+0=1
iv. 1 + 1 = 10
v. 1 + 1 + 1 = 11
1.4 Decimal to Binary
i. Convert Decimal to Binary:
a. Divide by 2 continuously till we get 1.
(33)10 = (100001)2
2 33 Remaind
er
2 16 1
2 8 0
2 4 0
2 2 0
1 0

Write the answer by taking remainder from bottom to


top.

You might also like