0% found this document useful (0 votes)
3 views7 pages

Python Basics Notes

The document provides an overview of Python basics for Class 9, covering data types, character sets, escape sequences, constants, keywords, and operators. It includes steps for writing a Python program, examples of variable usage, and explanations of comments and conditional statements. Additionally, it presents sample code for checking if a number is a single or two-digit number and prompts for a program to check for prime numbers.

Uploaded by

nlavanya821
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)
3 views7 pages

Python Basics Notes

The document provides an overview of Python basics for Class 9, covering data types, character sets, escape sequences, constants, keywords, and operators. It includes steps for writing a Python program, examples of variable usage, and explanations of comments and conditional statements. Additionally, it presents sample code for checking if a number is a single or two-digit number and prompts for a program to check for prime numbers.

Uploaded by

nlavanya821
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

Python Basics Notes - Class 9

1. Data Types
Data types define the kind of data a variable can hold.
Main data types in Python:
• int – integers (whole numbers). Example: 10, -5
• float – decimal numbers. Example: 3.14, -2.5
• str – string (text). Example: 'Hello', "Python"
• bool – Boolean values (True or False)
• list – collection of ordered, changeable items. Example: [1, 2, 3]
• tuple – ordered, unchangeable items. Example: (1, 2, 3)
• dict – key-value pairs. Example: {'name': 'John', 'age': 15}
• set – unordered, unique items. Example: {1, 2, 3}
2. Character Sets
Character set refers to all valid characters that Python can recognize.
Includes:
• Letters: A–Z, a–z
• Digits: 0–9
• Special Symbols: +, -, *, /, @, $, etc.
• Whitespaces: space, tab, newline
• Other Characters: _, #, etc.
3. Escape Sequences
Used to represent special characters in strings.
Examples:
• \n – New line
• \t – Tab space
• \\ – Backslash
• \' – Single quote
• \" – Double quote
4. Constants
Constants are fixed values that do not change during program execution.
Examples:
• Numeric constants: 10, 3.14
• String constants: "Hello", 'Python'
• Boolean constants: True, False
By convention, constants are written in uppercase (e.g., PI = 3.14).
5. Keywords
Keywords are reserved words in Python that have special meanings.
They cannot be used as variable names.
Examples:
and, or, not, if, else, elif, while, for, break, continue, True, False, None, def, return,
import, class, in, is
6. Operators
Operators are symbols used to perform operations on variables and values.
Types of Operators:
• Arithmetic: +, -, *, /, %, //, **
• Comparison: ==, !=, >, <, >=, <=
• Logical: and, or, not
• Assignment: =, +=, -=, *=, /=
• Membership: in, not in• Identity: is, is not
Steps to write a new python program
 Open Start Menu
 Go To IDLE
 Open File Menu
 Click on New File
 Write your program in this file
 Open File Menu, Click on Save as.
 Give desired name for your program file, select “save as type” as Python files.
 Click on Save
 To Run your program, go to Run, click on run module or press F5.

First Program done in class


class_name="9B and 9C"
no_of_students=20
date_today="20 November 2025"
print("This is class",class_name)
print("Today is",date_today)
print("There are",no_of_students,"students in today's class")

Output
This is class 9B and 9C
Today is 20 November 2025
There are 20 students in today's class

Using Variables
p_name="Virat Kohli"
cent=25
runs=15000
print("Player name=",p_name)
print("He made",cent,"centuries")
print(runs,"runs is the world record")
x,y=5,10 (Values assigned to x=5 and y=10)
x,y=y,x+10 (Value assigned to x=(value of y)
but not updated in original location till complete line runs.
Value assigned to y=(original value of x+10)

print(x,y)

Q) Write Output of the following codes

Assignment Operation
a,b,c=1,1,0
print("a=",a,"b=",b,"c=",c)
c,b=a,c+1
print("operation performed = c,b=a,c+3")
print("a=",a,"b=",b,"c=",c)
Book Q10

Solution
p=5
print("Value of p=",p)
p1=p*4
print("Value of p1=",p1)
p2=p1-5
print("Value of p2=",p2)

Solution
a=10
b=20
sum=a+b
print("Value of a=",a)
print("Value of b=",b)
print("Value of Sum=",sum)

.
Chapter 2
Comments :- Comments are reffered to as non executable statements.
Single line is commented done using # symbol.
Eg :- #print("operation performed = c,b=a,c+3")
In this code python will simply skip it from execution as it is commented using #
symbol

Normal Flow of control :- Sequential movement of control from one statement to


another.

Conditional Statements :- Conditional statements are used to branch out of normal


flow of execution based on logical conditions. Eg of conditional statements :- If, if and
only if, elif etc.
Example of Conditional statements
Program to check if a number is 2 digit number or single digit number using
input from user
x=int(input("Enter a number less than 100 to check if its 2 digit number or a single
digit number"))
if(x>5):
if(x>=10):
print("Given number is a two digit number")
elif(x<10):
print("Given number is a single digit number")
else:
print("input is less than 5")

Output
Enter a number less than 100 to check if its 2 digit number or a single digit number 25
Given number is a two digit number
Flow of execution of the above program

Task

Q ) Write a program to input a number from user, and check if it is a prime number, and show
appropriate response?

You might also like