print() to display text.
python
print("Hello, World!") for single-line comments, ''' or """ for multi-line comments.
python
This is a commentpython
name = "Alice" String
age = 25 Integer
height = 5.5 Floatint, float, str, bool, list, tuple, dict, set.python
fruits = ["apple", "banana", "cherry"] List
ages = (20, 25, 30) Tuple
person = {"name": "Alice", "age": 25} Dictionaryif, elif, and else to handle logic.
python
age = 18
if age >= 18:
print("You're an adult!")
else:
print("You're a minor.")python
for fruit in ["apple", "banana", "cherry"]:
print(fruit)python
count = 5
while count > 0:
print(count)
count -= 1def.
```python
def greet(name):
return f"Hello, {name}!"print(greet("Alice")) ```
try-except blocks to handle exceptions gracefully.
python
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")Data Analysis:
Use pandas and numpy to analyze data.
python
import pandas as pd
data = pd.DataFrame({"Name": ["Alice", "Bob"], "Age": [25, 30]})
print(data)
Web Scraping:
Use requests and BeautifulSoup to scrape data from websites.
```python
import requests
from bs4 import BeautifulSoup
response = requests.get("https://example.com") soup = BeautifulSoup(response.text, 'html.parser') print(soup.title.text) ```
os or shutil to automate file handling.
```python
import osos.rename("old_file.txt", "new_file.txt") ```