0% found this document useful (0 votes)
0 views14 pages

Python Theory With Examples PPT

This document provides a comprehensive overview of Python programming, covering key concepts such as variables, data types, operators, control statements, loops, functions, data structures, strings, file handling, object-oriented programming, modules, and exception handling. Each section includes examples to illustrate the concepts. It serves as a college-level introduction to Python with practical coding demonstrations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views14 pages

Python Theory With Examples PPT

This document provides a comprehensive overview of Python programming, covering key concepts such as variables, data types, operators, control statements, loops, functions, data structures, strings, file handling, object-oriented programming, modules, and exception handling. Each section includes examples to illustrate the concepts. It serves as a college-level introduction to Python with practical coding demonstrations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Python Theory + Examples

(College Level)
Full PPT with Concepts and Code
Examples
Introduction to Python
• Python is an interpreted, high-level language.
• Easy to learn and widely used.

• Example:
• print("Welcome to Python!")
Variables and Data Types
• Variables store data. Python types include int,
float, str, and bool.

• Example:
• age = 20
• price = 99.99
• name = "Alice"
• is_student = True
Operators
• Python supports arithmetic, comparison,
logical, and assignment operators.

• Example:
• a = 10
• b=3
• print(a + b)
• print(a > b)
• a += 2
Control Statements
• if, elif, and else help control flow based on
conditions.

• Example:
• marks = 75
• if marks >= 90:
• print("Grade A")
• elif marks >= 60:
• print("Grade B")
Loops
• Loops allow repetition using 'for' and 'while'.

• Example:
• for i in range(1, 6):
• print(i)
• i=1
• while i <= 5:
• print(i)
• i += 1
Functions
• Functions are reusable blocks of code.

• Example:
• def add(x, y):
• return x + y
• print(add(3, 5))
Data Structures
• Python has built-in types: List, Tuple, Set,
Dictionary.

• Example:
• fruits = ["apple", "banana"]
• colors = ("red", "blue")
• nums = {1, 2, 3}
• info = {"name": "John"}
Strings and Methods
• Strings support many built-in methods.

• Example:
• text = "hello"
• print(text.upper())
• print(text.replace("h", "H"))
File Handling
• Open files to read or write.

• Example:
• f = open("test.txt", "w")
• f.write("Hello")
• f.close()
• f = open("test.txt", "r")
• print(f.read())
OOP in Python
• Classes define objects. Use __init__ to
initialize.

• Example:
• class Student:
• def __init__(self, name):
• self.name = name
• s = Student("Alice")
Modules and Packages
• Modules are files with functions. Use 'import'
to use them.

• Example:
• import math
• print(math.sqrt(16))
Exception Handling
• Use try-except to catch errors.

• Example:
• try:
• x=1/0
• except ZeroDivisionError:
• print("Error")
Sample Programs
• Swap:
• a, b = 5, 10
• a, b = b, a

• Even/Odd:
• num = 4
• if num % 2 == 0:
• print("Even")
• else:

You might also like