Python Basics
Python is a high-level, interpreted programming language known for its simplicity and readability.
Installing Python
Download from: https://www.python.org/downloads/
Basic Syntax
Printing
print("Hello, World!")
Variables
x=5
y = "Hello"
Data Types
a = 10 # Integer
b = 10.5 # Float
c = "Python" # String
d = [1, 2, 3] # List
e = (4, 5, 6) # Tuple
f = {"name": "Alice", "age": 25} # Dictionary
---
NumPy
NumPy is a Python library for numerical computing.
Installing NumPy
pip install numpy
NumPy Basics
import numpy as np
Creating Arrays
arr = np.array([1, 2, 3, 4])
print(arr)
Reshaping Arrays
matrix = np.array([[1, 2], [3, 4]])
print(matrix.reshape(1, 4))
Mathematical Operations
print(np.mean(arr)) # Mean
print(np.median(arr)) # Median
print(np.std(arr)) # Standard Deviation
---
Pandas
Pandas is a library for data analysis and manipulation.
Installing Pandas
pip install pandas
Pandas Basics
import pandas as pd
Creating a DataFrame
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
print(df)
Reading a CSV file
df = pd.read_csv('data.csv')
Descriptive Statistics
print(df.describe())
Handling Missing Values
df.fillna(0, inplace=True)
---
Advanced OOPs in Python
Object-Oriented Programming (OOP) is a paradigm based on objects and classes.
Class and Objects
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def display(self):
print(f'Car: {self.brand} {self.model}')
car1 = Car('Tesla', 'Model S')
car1.display()
Inheritance
class ElectricCar(Car):
def __init__(self, brand, model, battery):
super().__init__(brand, model)
self.battery = battery
def show_battery(self):
print(f'Battery: {self.battery} kWh')
car2 = ElectricCar('Tesla', 'Model 3', 75)
car2.display()
car2.show_battery()
Polymorphism
class Animal:
def speak(self):
pass
class Dog(Animal):
def speak(self):
return "Woof!"
class Cat(Animal):
def speak(self):
return "Meow!"
animals = [Dog(), Cat()]
for animal in animals:
print(animal.speak())
---
TensorFlow
TensorFlow is an open-source framework for deep learning.
Installing TensorFlow
pip install tensorflow
Basic Example
import tensorflow as tf
Define a constant
x = tf.constant(5)
y = tf.constant(6)
z=x*y
print(f'Result: {z.numpy()}')
Building a Neural Network
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
Define a model
model = Sequential([
Dense(128, activation='relu', input_shape=(10,)),
Dense(64, activation='relu'),
Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
print(model.summary())
---
Git Basics (Version Control System)
Git is used for tracking code changes and collaboration.
Installing Git
Ubuntu/Debian
sudo apt install git
Mac (Homebrew)
brew install git
Basic Git Commands
git init # Initialize a repository
git status # Check status
git add . # Add all files
git commit -m "Message" # Commit changes
git push origin main # Push changes to GitHub
git pull origin main # Pull latest updates
---
Summary
- **Python:** Basic syntax, data types, variables
- **NumPy:** Arrays, reshaping, mathematical operations
- **Pandas:** DataFrames, handling missing values, CSV operations
- **OOP in Python:** Classes, inheritance, polymorphism
- **TensorFlow:** Neural networks and basic deep learning model
- **Git:** Version control commands
These tools and libraries are essential for Data Science and Software Development!