Grade 9 - Basics of Python
Grade 9 - Basics of Python
Install Python
Write simple commands in Python
Understand how to use variables in Python
I. INTRODUCTION
Python is one of the preferred programming
language used for AI based applications.
Web development
Software development
Game development
Artificial intelligence
Machine language
Data analytics
I. INTRODUCTION
TOP COMPANIES:
YOUTUBE
GOOGLE
DROPBOX
NETFLIX
INSTAGRAM
QUORA
FEATURES OF PYTHON:
1. Easy to learn
2. Readable
3. Standard library
4. Interactive mode
5. Portable
6. Database support
I. INTRODUCTION
1. EASY TO LEARN:
2. READABLE:
3. STANDARD LIBRARY:
4. INTERACTIVE MODE:
5. PORTABLE:
6. DATABASE SUPPORT:
print(“Hello”)
Python used input keyword to get the input from the user
and print keyword to display the output on the screen.
print (“Hi” )
print (“Learn” )
print (“About Python”)
print(“Hi”)
print(“Learn”)
print(“Python”)
The 3 line program above is correct and will run producing the
expected output.
II. LET’S DO PROGRAMMING
IN PYTHON
Hint:
If you use the Tab key instead of using spaces for the
purpose of indenting, then you must always use Tab key.
VALUES:
EXAMPLE:
number = 10
II. LET’S DO PROGRAMMING
IN PYTHON
REDECLARING A VARIABLE:
#Declaring a variable
Number = 100
#Display
print(“initial value of number is: “, Number)
#Re-declare the variable
Number = 200
print(“value of number after redeclaration:”, Number)
II. LET’S DO PROGRAMMING
IN PYTHON
DATA TYPES:
1. Numbers
2. Strings
3. List
4. Tuple
5. Dictionary
1. Numbers:
Numeric values are stored in number data type.
Python includes three numeric types to represent numbers:
integers, float, complex.
II. LET’S DO PROGRAMMING
IN PYTHON
Numbers:
int(signed integers): In Python, integers are
zero, positive or negative whole numbers without a
fractional part. Ex: 0, 100, -10
Numbers:
complex(complex numbers): A complex
number is a number with real and imaginary
components.
Ex: 5 + 2j
we must use j or J as imaginary components.
Using other characters it will show syntax error.
II. LET’S DO PROGRAMMING
IN PYTHON
Integer Float Complex
Example:
17 17.21 17.21j
-10 -17.12 21.17j
x=15.5
print(type(x)) <class ‘float’>
x=“Cybersquare"
print(type(x)) <class ‘str’>
x=True
print(type(x)) <class ‘bool’>
II. LET’S DO PROGRAMMING
IN PYTHON
Typecasting:
Integer int(variable_name)
Float float(variable_name)
String str(variable_name)
II. LET’S DO PROGRAMMING
IN PYTHON
2. String:
O/P:
Hello Python
II. LET’S DO PROGRAMMING
IN PYTHON
3. List:
syntax:
<listname>=[ ]
# initialize tuple
tup1 = (‘Python’ , ‘SQL’ )
# initialize another tuple
tup2 = (‘Learning’)
newtuple = tup1+tup2
print(newtuple)
II. LET’S DO PROGRAMMING
IN PYTHON
Program:
Ex2:
t1= (0,1,2, “Python”)
t2=(“SQL”, 26,25)
new=t1+t2
print(new)
II. LET’S DO PROGRAMMING
IN PYTHON
Dictionary:
1. Arithmetic operators
2. Relational operators
3. Logical operators
II. LET’S DO PROGRAMMING
IN PYTHON
1. Arithmetic Operators: Arithmetic operators
are used to do arithmetic calculations.
Operator Operation Example Result
+ Addition x=5+3 x=8
- Subtraction y=25-10 y=15
* Multiplication z=5*3 z=15
/ Division a=15/3 a=5
// Floor Division (rounds it to the b=10/4 b=2
nearest integer value)
** Exponentiation (calculate the c=2**3 c=8
power)
% Modulus (calculate remainder d=7%3 d=1
after division)
II. LET’S DO PROGRAMMING
IN PYTHON
2. Relational Operators: Relational operators are used
find out the relationship between two operands.
X Y X and Y X or Y Not X
True True True True False
True False False True False
False True False True True
False False False False True
Ex: 5>10 and 20<50 becomes False and True, and the
final result becomes False
II. LET’S DO PROGRAMMING
IN PYTHON
Assignment Operators: let us assume that the value of
X is 5.
Value of x
Operator Description Code Meaning after the
operation
=
Simple assignment operator.
Assign values from RHS value X=50 50
to LHS variable
Operator Description
** Exponentiation (raise to the power)
Expression:
An expression is a combination of operator and operands.
In any programming language, an expression is evaluated
as per the precedence of its operator. If there is more than
one operator in an expression, their precedence decides
which operation will be performed first.