Complete_Python_Guide_50_Pages
Complete_Python_Guide_50_Pages
1. Introduction to Python
Python is an interpreted, high-level programming language known for its simplicity and readability. It
is widely used in web development, data science, automation, and finance.
Python Features:
- Easy to learn
- Large community support
- Versatile
- Extensive libraries
Installing Python:
- Download from https://www.python.org
- Install Anaconda for data science work.
Basic Operations:
```python
x = 10
y=5
sum = x + y
Python Basics Guide
print(sum)
```
Python follows dynamic typing, meaning variable types do not need to be declared.
Example:
```python
x=5
y = 3.14
text = 'Hello'
flag = True
```
Type Conversion:
```python
num = '10'
num = int(num) # Convert string to integer
```
print(text.upper())
print(text.lower())
print(text.replace('fun', 'awesome'))
```
6. Conditional Statements
If-Else Example:
```python
num = 10
if num > 5:
print('Big number')
else:
print('Small number')
```
7. Loops in Python
Python Basics Guide
For Loop:
```python
for i in range(5):
print(i)
```
While Loop:
```python
x=0
while x < 3:
print(x)
x += 1
```
Defining Functions:
```python
def greet(name):
return 'Hello, ' + name
print(greet('Alice'))
```
9. File Handling
```python
with open('data.txt', 'r') as file:
content = file.read()
print(content)
```
Using Try-Except:
```python
try:
x=1/0
except ZeroDivisionError:
print('Cannot divide by zero!')
```
NumPy arrays:
```python
import numpy as np
arr = np.array([1, 2, 3])
print(arr)
```
Creating DataFrame:
```python
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
Python Basics Guide
print(df)
```
Plotting data:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.plot(x, y)
plt.show()
```
Web automation:
```python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://google.com')
```
Python Basics Guide
Using scikit-learn:
```python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
```
Debugging tips:
- Use print statements
- Use a debugger
- Write clean, modular code
Further Learning:
- Practice Python on W3Schools (https://www.w3schools.com/python/)
- Take online courses on Udemy, Coursera, or Codecademy
- Contribute to open-source projects on GitHub
- Build small projects to apply your knowledge
1. Introduction to Python
Python is an interpreted, high-level programming language known for its simplicity and readability. It
is widely used in web development, data science, automation, and finance.
Python Features:
- Easy to learn
- Large community support
- Versatile
- Extensive libraries
Installing Python:
- Download from https://www.python.org
- Install Anaconda for data science work.
Basic Operations:
```python
x = 10
y=5
sum = x + y
print(sum)
```
Python follows dynamic typing, meaning variable types do not need to be declared.
Example:
```python
x=5
y = 3.14
text = 'Hello'
flag = True
```
Type Conversion:
```python
num = '10'
num = int(num) # Convert string to integer
Python Basics Guide
```
6. Conditional Statements
If-Else Example:
```python
num = 10
if num > 5:
Python Basics Guide
print('Big number')
else:
print('Small number')
```
7. Loops in Python
For Loop:
```python
for i in range(5):
print(i)
```
While Loop:
```python
x=0
while x < 3:
print(x)
x += 1
```
Defining Functions:
```python
def greet(name):
return 'Hello, ' + name
print(greet('Alice'))
```
9. File Handling
Python Basics Guide
Using Try-Except:
```python
try:
x=1/0
except ZeroDivisionError:
print('Cannot divide by zero!')
```
NumPy arrays:
```python
import numpy as np
arr = np.array([1, 2, 3])
print(arr)
```
Python Basics Guide
Creating DataFrame:
```python
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
print(df)
```
Plotting data:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.plot(x, y)
plt.show()
```
Web automation:
```python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://google.com')
```
Using scikit-learn:
```python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
```
Debugging tips:
- Use print statements
- Use a debugger
- Write clean, modular code
Further Learning:
- Practice Python on W3Schools (https://www.w3schools.com/python/)
- Take online courses on Udemy, Coursera, or Codecademy
- Contribute to open-source projects on GitHub
- Build small projects to apply your knowledge
1. Introduction to Python
Python is an interpreted, high-level programming language known for its simplicity and readability. It
is widely used in web development, data science, automation, and finance.
Python Features:
- Easy to learn
- Large community support
- Versatile
- Extensive libraries
Installing Python:
- Download from https://www.python.org
- Install Anaconda for data science work.
Basic Operations:
```python
x = 10
y=5
sum = x + y
print(sum)
```
Python follows dynamic typing, meaning variable types do not need to be declared.
Example:
```python
x=5
y = 3.14
text = 'Hello'
flag = True
```
Python Basics Guide
Type Conversion:
```python
num = '10'
num = int(num) # Convert string to integer
```
6. Conditional Statements
Python Basics Guide
If-Else Example:
```python
num = 10
if num > 5:
print('Big number')
else:
print('Small number')
```
7. Loops in Python
For Loop:
```python
for i in range(5):
print(i)
```
While Loop:
```python
x=0
while x < 3:
print(x)
x += 1
```
Defining Functions:
```python
def greet(name):
return 'Hello, ' + name
print(greet('Alice'))
Python Basics Guide
```
9. File Handling
Using Try-Except:
```python
try:
x=1/0
except ZeroDivisionError:
print('Cannot divide by zero!')
```
NumPy arrays:
```python
import numpy as np
Python Basics Guide
Creating DataFrame:
```python
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
print(df)
```
Plotting data:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.plot(x, y)
plt.show()
```
print(df.head())
```
Web automation:
```python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://google.com')
```
Using scikit-learn:
```python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
```
Debugging tips:
- Use print statements
- Use a debugger
Python Basics Guide
Further Learning:
- Practice Python on W3Schools (https://www.w3schools.com/python/)
- Take online courses on Udemy, Coursera, or Codecademy
- Contribute to open-source projects on GitHub
- Build small projects to apply your knowledge