



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Beginner Level • Important Definitions • Syntax • Examples • Quick Revision
Fundamental Python concepts: features, data types, operators, control statements, loops, functions and commonly tested programs.
Important Definitions
Term Definition
Program Set of instructions to perform a task.
Algorithm Step-by-step procedure to solve a problem.
Flowchart Graphical representation of an algorithm.
Syntax Rules for writing valid code.
Variable A name that refers to a value.
Keyword Reserved word with a predefined meaning.
Identifier Name used for variables, functions, classes, etc.
Expression Values, variables and operators producing a result.
Statement An instruction executed by a program.
Comment Text ignored during execution; explains code.
name = "Aman" age = 17 x = 10 x = "Hello"
Type Meaning Example
int Integer 10, -
float Decimal 3.
complex Complex number 2+3j
bool Boolean True
str Text 'Python'
list Ordered, mutable [1, 2]
tuple Ordered, immutable (1, 2)
set Unique elements {1, 2}
dict Key-value pairs {'a': 1}
NoneType No value None
Mutable: list, set, dictionary. Immutable: int, float, string, tuple, Boolean.
4. Input, Output & Type Conversion
Output — print()
print("Hello World") print(10 + 5) # 15
Input — input()
name = input("Enter name: ") age = int(input("Enter age: ")) marks = float(input("Enter marks: "))
Type conversion
x = "10" print(int(x) + 5) # 15
5. Operators
Category Operators / Meaning
Arithmetic + add; − subtract; * multiply; / true division; // floor division; % remainder; ** power
Comparison ==, !=, >, <, >=, <= (return True/False)
Logical and: both true; or: at least one true; not: reverses truth value
Assignment =, +=, -=, *=, /=, //=, %=, **=
Membership in, not in — membership test
Identity is, is not — same object reference
6. Conditional Statements
if / if-else / if-elif-else
if n % 2 == 0: print("Even") else: print("Odd")
if marks >= 90: print("A") elif marks >= 60: print("B") else: print("C")
7. Loops
for loop and range()
for i in range(1, 6): print(i) # 1 to 5
while loop
i = 1 while i <= 5: print(i) i += 1
Statement Purpose
break Terminates nearest enclosing loop.
continue Skips rest of current iteration.
pass Does nothing; placeholder.
12. Errors and Exception Handling
Error type Meaning Example
Syntax error Breaks Python syntax rules Missing colon
Runtime error Occurs during execution Division by zero
Logical error Runs but gives wrong result Wrong operator
Exception handling
try: print(10 / 0) except ZeroDivisionError: print("Cannot divide by zero")
**13. Important Exam Programs
a = int(input("First: ")) b = int(input("Second: ")) print("Sum =", a + b)
2. Even or odd
n = int(input("Number: ")) if n % 2 == 0: print("Even") else: print("Odd")
3. Largest of two numbers
a = int(input("First: ")) b = int(input("Second: ")) if a > b: print(a) else: print(b)
4. Factorial
n = int(input("Number: ")) fact = 1 for i in range(1, n + 1): fact *= i print(fact)
For non-negative integers, factorial is the product of positive integers up to n; 0! = 1.
5. Multiplication table
n = int(input("Number: ")) for i in range(1, 11): print(n, "x", i, "=", n * i)
6. Sum of first N natural numbers
n = int(input("Number: ")) total = 0 for i in range(1, n + 1): total += i print(total)
14. Common Mistakes & Important Rules
15. Quick Revision Sheet
Very Short Answer
Short Answer
Programming Questions
Final Summary