0% found this document useful (0 votes)
22 views5 pages

Python

Uploaded by

phcs210001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Python

Uploaded by

phcs210001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Notes on Python Programming

1. Introduction

 Python is a high-level, interpreted, general-purpose


programming language created by Guido van Rossum in 1991.

 Known for simplicity, readability, and flexibility.

 Extensively used in web development, data science, AI/ML,


scripting, automation, networking, and GUI applications.

 Motto: “Python is simple and powerful.”

2. Features of Python

 Easy to learn & use → Syntax is close to English.

 Interpreted language → No need for compilation, executed line by


line.

 Portable → Runs on Windows, Linux, MacOS, etc.

 Object-Oriented → Supports classes, objects, inheritance,


polymorphism.

 Extensive Libraries → NumPy, Pandas, Matplotlib, TensorFlow,


Django, Flask, etc.

 Dynamic Typing → No need to declare variable types.

 Automatic Memory Management (Garbage collection).

 Integrated with other languages (C, C++, Java).

3. Python Basics

 Hello World Program:

 print("Hello, World!")

 Variables:

 x = 10
 name = "Alice"

 Data Types: int, float, str, bool, list, tuple, dict, set.

 Operators: Arithmetic, Relational, Logical, Assignment, Bitwise.

4. Control Statements

 Conditional (if-elif-else):

 age = 18

 if age >= 18:

 print("Eligible to vote")

 else:

 print("Not eligible")

 Loops:

o for loop → Iterates over a sequence.

o while loop → Runs until condition is false.

o break / continue / pass → Control flow inside loops.

5. Functions

 Defining functions:

 def greet(name):

 return "Hello " + name

 Built-in functions: print(), len(), type(), range(), input(), int(), str().

 Lambda (anonymous) functions:

 square = lambda x: x*x

6. Data Structures

 List: Ordered, mutable.

 fruits = ["apple", "banana", "cherry"]


 Tuple: Ordered, immutable.

 coordinates = (10, 20)

 Set: Unordered, unique elements.

 numbers = {1, 2, 3}

 Dictionary: Key-value pairs.

 student = {"name": "John", "age": 20}

7. Object-Oriented Programming (OOP)

 Class & Object:

 class Student:

 def __init__(self, name):

 self.name = name

 def display(self):

 print("Name:", self.name)

 s = Student("Alice")

 s.display()

 Supports inheritance, encapsulation, polymorphism,


abstraction.

8. File Handling

 Open file:

 f = open("data.txt", "r")

 Read/Write:

 data = f.read()

 f.write("Hello World")
 Always close file using f.close() or use with statement.

9. Exception Handling

 Used to handle runtime errors gracefully.

 try:

 x = 10 / 0

 except ZeroDivisionError:

 print("Cannot divide by zero!")

 finally:

 print("Done")

10. Python Modules & Packages

 Module: A Python file (.py) containing functions and classes.

 Package: Collection of modules with __init__.py.

 Importing:

 import math

 print(math.sqrt(16))

11. Python Libraries

 Data Science: NumPy, Pandas, Matplotlib, Seaborn.

 Machine Learning / AI: Scikit-learn, TensorFlow, PyTorch.

 Web Development: Django, Flask, FastAPI.

 Automation / Scripting: OS, Sys, Subprocess.

 Networking: Socket, Paramiko, Requests.

12. Advantages of Python

 Easy syntax, beginner-friendly.


 Large community support.

 Cross-platform compatibility.

 Rich ecosystem of libraries and frameworks.

 Used in multiple domains (AI, Web, IoT, Data Science).

13. Disadvantages of Python

 Slower than C/C++ (interpreted).

 Not ideal for mobile app development.

 Higher memory usage.

14. Applications of Python

 Web development.

 Data Science and Machine Learning.

 Artificial Intelligence.

 Automation & Scripting.

 Game development.

 Networking and Security.

 IoT (Internet of Things).

✅ Summary:
Python is a versatile, powerful, and easy-to-learn programming
language widely used in modern technologies like AI, ML, Data Science,
and Web Development. With its readable syntax, large libraries, and
portability, Python is one of the most popular languages today.

You might also like