Welcome to Python
Programming
• In this course, you'll learn Python from basics to
advanced topics like OOP, file handling, and more.
• Let's get started!
What is Python?
• Python is a high-level, interpreted programming
language.
• It is widely used in web development, data science,
AI, automation, and more.
Why Learn Python?
• - Easy to read and write
• - Large community and library support
• - Used by companies like Google, Netflix, and NASA
Installing Python
• Download from: https://python.org
• Use IDEs like VS Code, PyCharm, or Jupyter
Notebook for writing Python code.
Hello World Program
• Code:
• print('Hello, World!')
• This prints 'Hello, World!' to the screen.
Variables in Python
• Variables are used to store data.
• Example:
• x = 10
• y = 'Hello'
• print(x, y)
Data Types
• Common data types:
• - int
• - float
• - str
• - bool
• - list
• - tuple
• - dict
Type Conversion
• Use functions like int(), str(), float(), list() to convert
between types.
Input and Output
• Getting input:
• name = input('Enter your name: ')
• print('Hello', name)
Operators
• Types of operators:
• - Arithmetic (+, -, *, /)
• - Assignment (=, +=)
• - Comparison (==, !=)
• - Logical (and, or, not)
Conditional Statements
• if condition:
• # code
• elif condition:
• # code
• else:
• # code
Loops - For
• for i in range(5):
• print(i)
• Prints 0 to 4.
Loops - While
• count = 0
• while count < 5:
• print(count)
• count += 1
Break and Continue
• Used to control loop flow.
• break - exits loop
• continue - skips iteration
Functions
• def greet(name):
• print('Hello', name)
• greet('Alice')
Function Arguments
• def add(a, b):
• return a + b
• print(add(5, 3))
Default Parameters
• def greet(name='User'):
• print('Hello', name)
Return Statement
• Used to return result from a function.
• def square(x):
• return x * x
Lists
• fruits = ['apple', 'banana']
• print(fruits[0])
List Methods
• append(), remove(), sort(), reverse()
• fruits.append('mango')
Tuples
• Immutable lists
• t = (1, 2, 3)
• print(t[0])
Dictionaries
• key-value pairs
• d = {'name': 'Alice', 'age': 25}
• print(d['name'])
Sets
• Unordered collection of unique items.
• s = {1, 2, 3}
String Methods
• 'hello'.upper()
• 'Python'.lower()
• 'hi'.replace('h', 'b')
String Formatting
• name = 'John'
• print(f'Hello {name}')
Nested Loops
• for i in range(3):
• for j in range(2):
• print(i, j)
List Comprehensions
• [x for x in range(10) if x % 2 == 0]
Try-Except Blocks
• try:
• x = 1 / 0
• except ZeroDivisionError:
• print('Error')
File Handling - Read
• f = open('file.txt')
• print(f.read())
• f.close()
File Handling - Write
• f = open('file.txt', 'w')
• f.write('Hello')
• f.close()
With Statement
• with open('file.txt') as f:
• print(f.read())
OOP: Classes and Objects
• class Person:
• def __init__(self, name):
• self.name = name
Creating an Object
• p = Person('Alice')
• print(p.name)
Class Methods
• class Dog:
• def bark(self):
• print('Woof!')
Inheritance
• class Animal:
• def eat(self): print('eating')
• class Dog(Animal):
• def bark(self): print('barking')
Polymorphism
• Different classes can have same method names.
• E.g., draw() in Circle and Square.
Encapsulation
• Keeping data safe inside objects using private
members.
Lambda Functions
• square = lambda x: x*x
• print(square(5))
Map and Filter
• list(map(lambda x: x*2, [1, 2, 3]))
Modules and Packages
• import math
• print(math.sqrt(16))
Built-in Functions
• len(), max(), min(), sum(), type(), etc.
Exception Types
• ZeroDivisionError, FileNotFoundError, ValueError,
etc.
Decorators
• Used to modify functions
• @decorator_name
• def func(): pass
Generators
• yield keyword for iterators
• def gen(): yield 1
Comprehensions
• Set: {x for x in range(5)}
• Dict: {x: x*x for x in range(5)}
Python Libraries
• NumPy, Pandas, Matplotlib, Requests, etc.
Installing Packages
• Use pip:
• pip install numpy
Summary
• You’ve learned Python basics to OOP and files. Keep
practicing!
Thank You!
• Follow @DataWithYogesh for more tech content
and courses!

Python_Notes_practical_With_ripocybertech.pptx