RegEx, PIP & Try/Except
The re module matches patterns in text. re.search(), re.findall(), re.sub() are common.
Python RegEx
The re module matches patterns in text. re.search(), re.findall(), re.sub() are common.
Raw strings r"pattern" avoid backslash escaping headaches.
Real-life example: RegEx is a custom search filter — find all emails in a paragraph, not just one word.
import re
text = "Contact: support@knowvora.com"
match = re.search(r"[\w.-]+@[\w.-]+", text)
print(match.group() if match else "No email")Python PIP
pip installs third-party packages: pip install requests, pip list, pip show package.
Use python -m pip install package for reliability. Pin versions in requirements.txt for projects.
Real-life example: pip is an app store for Python — one command downloads tools others built.
# Run in terminal — not inside .py file
# python -m pip install requests
# python -m pip list
# python -m pip freeze > requirements.txtPython Try...Except
try/except catches errors so programs do not crash. Use specific exceptions like ValueError, FileNotFoundError.
else runs if no error; finally always runs (cleanup).
Real-life example: try/except is a safety net under a trapeze — the show continues even if one move fails.
try:
score = int("abc")
except ValueError:
print("Invalid number")
finally:
print("Attempt finished")