Python Basics
Python is a powerful, high-level, and easy-to-learn programming
language. It is widely used for web development, data science,
automation, AI, and more.
## Variables and Data Types:
Python supports multiple data types such as:
- Integer (`int`): Whole numbers like 1, 100, -5
- Floating Point (`float`): Numbers with decimals like 2.5, -0.99
- String (`str`): Text data like "Hello World"
- Boolean (`bool`): `True` or `False`
- Lists, Tuples, Dictionaries, and Sets
### Example:
```python
x = 10 # Integer
y = 3.14 # Float
name = "John" # String
is_valid = True # Boolean
```
## Conditional Statements:
Python supports `if`, `elif`, and `else` for decision-making.
```python
age = 20
if age >= 18:
print("You are an adult")
else:
print("You are a minor")
```
## Loops:
Python has `for` and `while` loops.
```python
for i in range(5):
print(i)
count = 0
while count < 5:
print(count)
count += 1
```
NumPy
NumPy (Numerical Python) is used for scientific computing,
supporting arrays and mathematical functions.
## Installing NumPy:
```bash
pip install numpy
```
## Creating Arrays:
```python
import numpy as np
arr = [Link]([1, 2, 3, 4, 5])
print(arr)
```
## Array Operations:
```python
a = [Link]([10, 20, 30])
b = [Link]([5, 10, 15])
print(a + b) # Addition
print(a * 2) # Scalar multiplication
```
## Reshaping Arrays:
```python
matrix = [Link]([[1, 2], [3, 4]])
reshaped = [Link](1, 4)
print(reshaped)
```
Pandas
Pandas is used for data manipulation and analysis.
## Creating DataFrames:
```python
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = [Link](data)
print(df)
```
## Reading CSV Files:
```python
df = pd.read_csv('[Link]')
print([Link]())
```
## Handling Missing Values:
```python
[Link](0, inplace=True)
print(df)
```
OOP in Python
Object-Oriented Programming (OOP) allows modular and reusable
code.
## Creating a Class:
```python
class Car:
def __init__(self, brand, model):
[Link] = brand
[Link] = model
def display(self):
print(f'Car: {[Link]} {[Link]}')
car1 = Car('Tesla', 'Model S')
[Link]()
```
## Inheritance:
```python
class ElectricCar(Car):
def __init__(self, brand, model, battery):
super().__init__(brand, model)
[Link] = battery
def show_battery(self):
print(f'Battery: {[Link]} kWh')
car2 = ElectricCar('Tesla', 'Model 3', 75)
[Link]()
car2.show_battery()
```
TensorFlow
TensorFlow is an open-source deep learning framework.
## Installing TensorFlow:
```bash
pip install tensorflow
```
## Basic TensorFlow Example:
```python
import tensorflow as tf
x = [Link](5)
y = [Link](6)
z=x*y
print(f'Result: {[Link]()}')
```
Git
Git is a version control system used to track code changes.
## Installing Git:
```bash
# Ubuntu/Debian
sudo apt install git
# Mac (Homebrew)
brew install git
```
## Git Commands:
```bash
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
```