IT Skills

Python Crash Course Basics And Examples





1. Basics of Python Syntax

  • Printing: Use print() to display text. python print("Hello, World!")
  • Comments: Use for single-line comments, ''' or """ for multi-line comments. python This is a comment
  • Variables: No need to declare types explicitly. python name = "Alice" String age = 25 Integer height = 5.5 Float

2. Data Types

  • Common types: int, float, str, bool, list, tuple, dict, set.
  • Example: Manipulating data types. python fruits = ["apple", "banana", "cherry"] List ages = (20, 25, 30) Tuple person = {"name": "Alice", "age": 25} Dictionary

3. Conditionals

  • Use if, elif, and else to handle logic. python age = 18 if age >= 18: print("You're an adult!") else: print("You're a minor.")

4. Loops

  • For loop: Iterate over a sequence. python for fruit in ["apple", "banana", "cherry"]: print(fruit)
  • While loop: Repeat while a condition is true. python count = 5 while count > 0: print(count) count -= 1

5. Functions?

  • Encapsulate reusable blocks of code with def. ```python def greet(name): return f"Hello, {name}!"

print(greet("Alice")) ```


6. Error Handling

  • Use try-except blocks to handle exceptions gracefully. python try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero!")

7. Real-World Situations

  1. 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)

  2. 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) ```

  1. Automating Tasks: Use os or shutil to automate file handling. ```python import os

os.rename("old_file.txt", "new_file.txt") ```


8. Resources to Practice

  • Platforms: LeetCode, HackerRank, Replit
  • Books: "Automate the Boring Stuff with Python" and "Python Crash Course" by Eric Matthes.

If you liked this, consider supporting us by checking out Tiny Skills - 250+ Top Work & Personal Skills Made Easy