Introduction to Python
Programming
By Aparna Samantaray
What is Python?
• Python is a high-level, interpreted programming language.
• Created by Guido van Rossum in 1989.
• Known for its simple syntax and readability.
• Widely used in web development, data science, automation,
and more.
C vs Java vs Python
C Java
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
printf("%d\n", i); System.out.println(i);
} }
Python
for i in range(5):
print(i)
Key Features of Python
• Easy to Learn and Use: Simple, human-readable syntax.
• Interpreted Language: No need for compilation, runs
directly from source code.
• Versatile: Can be used for web development, automation,
data analysis, etc.
• Open Source: Free to use and has a large supportive
community.
• Extensive Libraries: Includes libraries like NumPy,
Pandas, Flask, Django.
Python Syntax Basics
• Indentation: Python uses indentation (whitespace) to
define code blocks.
Example of indentation in Python
def greet(name):
if name:
print("Hello, " + name + "!")
else:
print("Hello, World!")
names = ["Alice", "Bob", None, "Charlie"]
for name in names:
greet(name) # This line is inside the for loop
Python Variables and Data Types
• Variables: Containers for storing data values.
• Data Types: Integer (int), Float (float), String (str), List,
Tuple, Dictionary, etc.
Example:
age = 25
height = 5.9
name = "John"
fruits = ["apple", "banana", "cherry"]
coordinates = (10, 20)
person = {"name": "Alice", "age": 25, "city": "New York"}
Python Control Structures…
• Conditional Statements (if, elif, else)
• Loops: for and while loops to repeat code.
Example:
# Example using if, elif, and else
age = 18
if age >= 18:
print("You are an adult.")
elif age >= 13: Output:
print("You are a teenager.") You are an adult
else:
print("You are a child.")
# Example of for loop Output:
fruits = ["apple", "banana", "cherry"] apple
for fruit in fruits: banana
print(fruit) cherry
# Example of while loop
Output:
counter = 0
Counter is: 0
while counter < 3: Counter is: 1
print("Counter is:", counter) Counter is: 2
counter += 1
Functions in Python
• Functions allow you to organize code into reusable blocks.
• Defined using the def keyword.
Example:
def greet(name):
return "Hello " + name
print(greet("Alice"))
Output:
Hello Alice
Python Lists and Loops
• Lists: Store multiple items in a single variable.
Example:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Output:
apple
banana
cherry
Python Libraries and Modules
• Libraries: Pre-written code that can be used to perform
common tasks.
• Modules: Python files containing related functions and
variables.
Example:
import math
print(math.sqrt(16)) Output: 4.0
Python Modules and Libraries Used in
Different Areas
Data Science Web Automation & Artificial Game
& Machine Development Scripting Intelligence & Development
Learning Deep
Learning
Pandas Django Selenium OpenCV Pygame
NumPy Flask PyAutoGUI NLTK / SpaCy Panda3D
Scikitlearn FastAPI Requests TensorFlow / PyKyra
Matplotlib / BeautifulSoup os / shutil Keras / PyTorch
Seaborn: Requests schedule: Scikit-learn
TensorFlow /
PyTorch
Keras
Conclusion & Resources
• Python is a versatile and easy-to-learn language.
• Ideal for beginners and experts alike.
• Resources to Learn More:
Official Python Documentation: https://python.org
Online Tutorials: Codecademy, W3Schools, Coursera, etc.
Python Community: Stack Overflow, Reddit, etc.
Thank You