0% found this document useful (0 votes)
10 views4 pages

Python Notes Compressed

This document provides class notes on Python programming, covering its definition, features, data types, operators, control statements, functions, and object-oriented programming concepts. It includes examples of code for displaying information, calculating areas, checking number types, and defining classes and functions. The notes emphasize Python's simplicity, versatility, and its application in various fields.

Uploaded by

saleemyoungarmy6
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)
10 views4 pages

Python Notes Compressed

This document provides class notes on Python programming, covering its definition, features, data types, operators, control statements, functions, and object-oriented programming concepts. It includes examples of code for displaying information, calculating areas, checking number types, and defining classes and functions. The notes emphasize Python's simplicity, versatility, and its application in various fields.

Uploaded by

saleemyoungarmy6
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 PROGRAMMING – CLASS NOTES

1. (a) What is Python?


Python is a high-level, general-purpose programming language known for its simplicity and readability.
It supports multiple programming paradigms, including procedural, functional, and object-oriented
programming. Because of its ease of use, Python is widely used in fields like web development, data
science, machine learning, automation, and more.

Four (4) Features That Make Python Popular


1. Easy to Read and Learn
Python’s syntax is simple and close to English, making it beginner-friendly.
2. Cross-Platform Language
Python runs on Windows, macOS, Linux, and many other systems without modification.
3. Large Standard Library
Comes with built-in modules and functions that simplify tasks like math calculations, file
handling, web operations, etc.
4. Supports Multiple Programming Paradigms
It allows procedural, object-oriented, and functional programming.

(b) Python Program to Display Name and Department


print("Name: Salim Bello")
print("Department: Computer Science")

2. (a) Definition of a Variable


A variable in Python is a memory location used to store data values. It acts as a container for values
that may change during program execution.

Three (3) Data Types in Python


Data Type Description Example
int (Integer) Whole numbers without decimals age = 20
float Numbers with decimal points price = 12.75
str (String) Text enclosed in quotes name = "Aisha"

(b) Dictionary to Store Student Information


student = {
"name": "Salim Bello",
"age": 70,
"cgpa": 3.30
}

print("Student Name:", student["name"])


print("Age:", student["age"])
print("CGPA:", student["cgpa"])

3. (a) Arithmetic vs Comparison Operators


Arithmetic
Function Example
Operators
+ Addition 5 + 3 = 8
* Multiplication 4 * 2 = 8
Comparison
Function Example
Operators
5 == 5 →
== Checks equality
True
7 > 3 →
> Greater than
True

(b) Expression to Calculate Area of a Circle


import math

radius = 5
area = [Link] * radius**2
print("Area of Circle:", area)

4. (a) if, elif, else Statements


These are decision-making statements that allow a program to choose different actions based on
conditions.
 if → executes when the first condition is true

 elif → executes if previous if is false and its condition is true

 else → runs when all conditions fail


Example Flow:
if condition1:
# executes if condition1 is true
elif condition2:
# executes if condition1 is false but condition2 is true
else:
# executes when none of the above are true

(b) Program to Check Number Type


num = float(input("Enter a number: "))

if num > 0:
print("Positive Number")
elif num < 0:
print("Negative Number")
else:
print("Zero")
5. (a) Definition of a Function
A function is a block of reusable code that performs a specific task. It is defined using the def
keyword.

Advantages of Using Functions


1. Makes code reusable and reduces repetition.
2. Improves organization, readability, and structure.
3. Makes debugging easier by isolating errors.
4. Allows collaboration—each function can be written by different people.

(b) Function to Sum Even Numbers


def sum_even(numbers):
total = 0
for num in numbers:
if num % 2 == 0:
total += num
return total

print(sum_even([1, 2, 3, 4, 6])) # Output: 12

6. (a) Concept of Object-Oriented Programming (OOP)


OOP is a programming paradigm based on the concept of objects which contain both data (attributes)
and behaviors (methods).

Three Key Principles


1. Encapsulation – Bundling data and methods inside a class.
2. Inheritance – Ability of a class to inherit properties from another.
3. Polymorphism – Ability to use a method in different forms or behaviors.

(b) Python Class Example


class Book:
def __init__(self, title, author):
[Link] = title
[Link] = author

def display(self):
print("Title:", [Link])
print("Author:", [Link])

# Example usage
book1 = Book("Python Programming", "Salim Bello")
[Link]()

You might also like