Getting Started with Python (Class 11 Computer
Science)
What is Python?
Python is a high-level, easy-to-learn programming language used to create applications,
websites, automation tools, data analysis programs, and more.
It is popular because:
Simple syntax (easy to read like English)
Fewer lines of code
Free and open source
Works on Windows, Mac, Linux
Used in AI, Data Science, Web Development
Features of Python
Interpreted Language → Runs line by line.
Platform Independent → Same program runs on any OS.
Dynamically Typed → No need to declare data types.
Object-Oriented → Supports classes and objects.
Large Library Support → Many built-in modules available.
Installing Python (Basic Idea
1. Download Python from official website.
2. Install it.
3. Open IDLE / Python Interpreter.
4. Start typing programs.
First Python Program
SOURCE CODE:
print("Hello, World!")
OUTPUT:
Hello, World!
Python as an Interpreter
Python executes code line by line, so errors are shown immediately.
Example:
print("Hi")
print("Welcome")
Tokens in Python
Tokens = Smallest units of a program.
Types:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators
Keywords
Keywords are reserved words with special meaning.
Examples:
if, else, while, for, True, False, None, break, continue
You cannot use them as variable names.
Identifiers (Variable Names)
Identifiers are names given to variables, functions, etc.
Rules:
Must start with letter or _
Cannot start with number
No spaces allowed
Cannot use keywords
Valid:
marks
_total
name1
Invalid:
1name
my name
if
Variables
A variable is used to store data.
x = 10
name = "Rahul"
No need to declare type!
Data Types in Python
Data Type Example
int 10
float 5.5
str "Hello"
bool True
Example:
a = 5
b = 2.5
c = "Python"
d = True
Taking Input from User
name = input("Enter your name: ")
print(name)
input() always takes string input.
Type Conversion (Casting)
Convert one type into another:
age = int(input("Enter age: "))
Function Use
int() Convert to integer
float() Convert to decimal
str() Convert to string
Operators in Python
Arithmetic Operators
+ Addition
- Subtraction
* Multiplication
/ Division
// Floor Division
% Modulus
** Power
Example:
a = 10
b = 3
print(a + b)
print(a % b)
Writing Comments
Comments are notes ignored by Python.
# This is a comment
Used to explain code.
Simple Python Program (Example)
Program to Find Sum of Two Numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
sum = a + b
print("Sum =", sum)
Errors in Python
Error Meaning
Syntax Error Wrong format
Runtime Error Happens during execution
Logical Error Wrong output
Python Statements & Indentation
Python uses indentation (spaces) instead of { }.
Example:
if 5 > 2:
print("Five is greater")
Indentation is very important in Python