Python Programming Notes (BS Level)
These notes cover the fundamentals of Python programming and introductory concepts of programming for BS level
students. The content is simple, practical, and easy to understand.
1. Definition of Python
Python is a high-level, interpreted, and general-purpose programming language created by Guido van Rossum in
1991. It is easy to learn because of its simple syntax. Python is widely used in web development, artificial intelligence,
data science, automation, cybersecurity, and software development.
2. What is Programming?
Programming is the process of giving instructions to a computer so it can perform tasks. These instructions are written
in a programming language. A programmer writes code to solve problems, perform calculations, or automate tasks.
3. Data Types in Python
Data types define the type of data a variable can store. Common Python data types include:
int → Integer values such as 5, 100, -9
float → Decimal values such as 3.14, 9.8
str → Text values such as "Hello"
bool → True or False values
4. Variables
Variables are containers used to store data values. Example:
x = 10
name = "Ali"
price = 99.5
Rules:
• Variable names cannot start with numbers.
• Use meaningful names.
• Python is case-sensitive.
5. print() and input() Functions
print() is used to display output on the screen.
Example:
print("Welcome")
input() is used to take input from the user.
Example:
name = input("Enter your name: ")
print("Hello", name)
6. if and if-else Statements
Conditional statements are used to make decisions.
Example of if:
age = 18
if age >= 18:
print("Adult")
Example of if-else:
marks = 40
if marks >= 50:
print("Pass")
else:
print("Fail")
7. for Loop with Practical Implementation
A loop is used to repeat tasks. The for loop repeats a block of code multiple times.
Example:
for i in range(1, 6):
print(i)
Practical Example: Display multiplication table of 2
for i in range(1, 11):
print("2 x", i, "=", 2*i)
8. %d and Formatting in C Language
In the C language, format specifiers are used with printf() to display data.
Common format specifiers:
%d → Integer
%f → Float
%c → Character
%s → String
Example:
int age = 20;
printf("Age = %d", age);
9. Terminal and IDE
Terminal: A terminal is a text-based interface used to run commands and programs. Example terminals: Command
Prompt, PowerShell, Linux Terminal.
IDE (Integrated Development Environment): Software used to write, edit, run, and debug code. Examples:
PyCharm, VS Code, IDLE.
Simple Diagram: Programming Process
Input Processing Output
Simple Diagram: IDE Components
IDE Window
File Explorer Code Editor Output Console
Practice MCQs
Q1. Python is a _____ language.
A) Low-level B) Machine C) High-level D) Binary
Answer: High-level
Q2. Which function is used to display output?
A) input() B) show() C) print() D) display()
Answer: print()
Q3. Which data type stores decimal values?
A) int B) float C) bool D) str
Answer: float
Q4. Which keyword is used for conditions?
A) loop B) if C) print D) input
Answer: if
Q5. A variable stores _____.
A) Programs B) Data C) Functions D) Errors
Answer: Data
Q6. Which loop repeats code multiple times?
A) if B) switch C) for D) print
Answer: for
Q7. What does %d represent in C?
A) Float B) Character C) Integer D) String
Answer: Integer
Q8. Which function takes user input?
A) print() B) show() C) input() D) type()
Answer: input()
Q9. Python is case _____.
A) free B) insensitive C) sensitive D) locked
Answer: sensitive
Q10. An IDE helps programmers to _____.
A) Cook food B) Write and run code C) Play games D) Design clothes
Answer: Write and run code
Short Questions
1. Define Python.
2. What is a variable?
3. Write the syntax of print() function.
4. What is the use of input() function?
5. Differentiate between int and float.
Long Questions
1. Explain different data types in Python with examples.
2. Explain the working of if-else statements and for loops with practical examples.
End of Notes — Practice the examples regularly to improve programming skills.