You’re the Expert!

pynfinity

Build mountain with each pebble 🧗

Topics | Stepping Stones
Official Guides
Community Contributions
📖
Guides
In-depth topic walkthroughs with examples
19 topics
Bytes
Detailed notes, tutorials & code deep-dives
83 posts
💎
Bits
Quick code snippets — read in one scroll
42 snippets
📖

Official Guides

Bytes — Tutorials & Deep-Dives

🧩
🧩 Regular Expressions
Regular expressions are a powerful tool for various kinds of string manipulation.
pynfinity 2027-06-23
⏳ Time Series Resampling
Resampling allows you to change the frequency of your time series data, e.g., from daily to monthly.
santoshtvk 2028-01-09
🎛️
🎛️ Multiprocessing
Multiprocessing allows you to create processes, which can run in parallel on multiple CPU cores.
pynfinity 2025-01-23
🐳
🐳 Dockerfiles
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
pynfinity 2023-10-31
📸
📸 OpenCV Image Reading
OpenCV is a huge open-source library for computer vision, machine learning, and image processing.
pynfinity 2025-05-02
⏳ Time Series Resampling
Resampling allows you to change the frequency of your time series data, e.g., from daily to monthly.
santoshtvk 2026-01-01
📄
📄 JSON Handling
JSON is a lightweight data interchange format inspired by JavaScript object literal syntax.
pynfinity 2024-09-15
⚡ Python async/await — Asynchronous Programming Guide
asyncio enables concurrent I/O-bound tasks in Python without threads. Learn async/await to write high-performance APIs and web scrapers.
santoshtvk 2025-12-02
♾️
♾️ Python Generators — Memory-Efficient Iterators
Generators produce values on demand instead of storing everything in memory. Perfect for large datasets, streaming, and infinite sequences.
santoshtvk 2026-09-01
🔐
🔐 Python Environment Variables — Managing Config Safely
Never hardcode secrets in Python code. Environment variables and .env files keep API keys, passwords, and configs out of source code.
santoshtvk 2026-05-15
📚
📚 Collections Module
This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers.
pynfinity 2023-04-17
🚪
🚪 Context Managers
Context managers allow you to allocate and release resources precisely when you want to.
pynfinity 2023-05-13
⚡ FastAPI Endpoints
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+.
pynfinity 2023-12-24
🐼
🐼 Pandas DataFrames
Pandas DataFrame is a primary two-dimensional tabular data structure in the pandas Python library. They allow you to store and manipulate tabular data efficiently.
santoshtvk 2025-07-01
🏷️
🏷️ Type Hinting
Type hinting helps you document your code and catch errors early.
santoshtvk 2028-01-29
✍️
✍️ Python f-Strings — The Modern Way to Format Strings
f-strings (formatted string literals) are the fastest, most readable way to format strings in Python 3.6+. Master them completely.
santoshtvk 2026-07-14
📦
📦 Dataclasses
Dataclasses provide a decorator and functions for automatically adding generated special methods to classes.
pynfinity 2023-08-19
🖥️
🖥️ Python argparse — Building Command-Line Tools
argparse turns Python scripts into professional CLI tools with automatic help messages, type validation, and optional/required arguments.
santoshtvk 2025-11-21
📊
📊 Python dataclasses — Clean Data Models in Python
The @dataclass decorator auto-generates boilerplate code for data-holding classes — __init__, __repr__, __eq__ all for free.
santoshtvk 2026-02-06
📧
📧 How to Send Email with Python
Python makes sending emails straightforward using the smtplib module. Learn to send plain text, HTML emails, and attachments.
santoshtvk 2024-06-12
🖥️
🖥️ OS Module
The os module provides a portable way of using operating system dependent functionality.
santoshtvk 2025-05-27
📂
📂 How to Read a CSV File in Python
Reading CSV files is one of the most common tasks in Python. The built-in csv module and pandas both make it simple.
santoshtvk 2024-05-23
🕸️
🕸️ NetworkX Graphs
NetworkX is a Python package for the creation, manipulation, and study of the structure of complex networks.
pynfinity 2025-03-06
🕷️
🕷️ Python Web Scraping with Selenium — Dynamic Sites
Selenium controls a real browser for scraping JavaScript-heavy sites that BeautifulSoup can't handle. Automate login, fill forms, click buttons.
santoshtvk 2027-05-16
✨ Jupyter Magic Commands
Magic commands are special commands that you can run in Jupyter notebooks to perform special tasks.
santoshtvk 2024-10-17
📊
📊 Interactive Plots with Plotly
Plotly allows you to create interactive charts that you can zoom, pan, and hover over.
santoshtvk 2024-07-23
🌲
🌲 Git Basics
Git is a distributed version control system for tracking changes in source code during software development.
pynfinity 2024-04-16
🎀
🎀 Decorators
Decorators allow you to modify the behavior of a function or class.
pynfinity 2023-09-24
📁
📁 Python File Handling — Read, Write, and Append Files
Python file handling covers reading, writing, and appending data. The 'with' statement ensures files are always closed properly.
santoshtvk 2026-08-08
🔍
🔍 Python Type Hints — Write Safer, Self-Documenting Code
Type hints make Python code more readable, catch bugs earlier, and supercharge IDE autocomplete. Introduced in Python 3.5, improved in every version since.
santoshtvk 2027-05-05
🪵
🪵 Logging
Logging is a means of tracking events that happen when some software runs.
santoshtvk 2024-12-03
☁️
☁️ AWS S3 with Boto3
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python.
santoshtvk 2023-03-18
🔥
🔥 Seaborn Heatmaps
Seaborn makes it easy to create attractive heatmaps to visualize correlation matrices or 2D data.
santoshtvk 2027-08-28
⏳ AsyncIO
AsyncIO is a library to write concurrent code using the async/await syntax.
santoshtvk 2023-02-23
➗ Math Module
This module provides access to the mathematical functions defined by the C standard.
pynfinity 2024-12-18
📖
📖 Python Dictionary Methods — Complete Guide
Python dictionaries are flexible key-value stores. Mastering dict methods unlocks faster, more readable data manipulation code.
santoshtvk 2026-04-15
📦
📦 Virtual Environments
Virtual environments allow you to manage dependencies for different projects separately.
santoshtvk 2028-02-11
⚡ Generators
Generators are a simple way of creating iterators. They use the `yield` statement.
pynfinity 2024-03-14
🧵
🧵 Multithreading
Threading allows you to run multiple operations concurrently in a single process.
pynfinity 2025-02-09
📉
📉 Statsmodels OLS
Statsmodels allows you to explore data, estimate statistical models, and perform statistical tests.
santoshtvk 2027-10-18
⚙️
⚙️ Sys Module
The sys module provides access to some variables used or maintained by the interpreter.
santoshtvk 2027-11-21
🗺️
🗺️ Folium Maps
Folium builds on the data wrangling strengths of the Python ecosystem and the mapping strengths of the Leaflet.js library.
pynfinity 2024-01-31
🧹
🧹 Data Cleaning with Dropna
Missing data is a common problem. Pandas provides `dropna()` to easily remove rows or columns with null values.
santoshtvk 2026-01-01
🛡️
🛡️ Pydantic Models
Pydantic performs data validation and settings management using Python type annotations.
pynfinity 2025-09-10
🎁
🎁 Python Decorators Explained with Examples
Decorators are one of Python's most elegant features. They wrap functions to add extra behaviour — without changing the original function code.
santoshtvk 2026-03-19
🧪
🧪 Python Testing with unittest and pytest
Testing your Python code prevents bugs from reaching production. pytest makes writing and running tests fast, readable, and enjoyable.
santoshtvk 2027-04-01
🤖
🤖 Scikit-Learn Linear Regression
Linear Regression is the 'Hello World' of Machine Learning. Scikit-Learn makes it a breeze to implement.
pynfinity 2026-01-01
🔮
🔮 Python Sets — The Underrated Power of Set Operations
Python sets are unordered collections of unique elements. Set operations like union, intersection, and difference are lightning fast.
santoshtvk 2027-03-01
🔢
🔢 NumPy Arrays
NumPy arrays are faster and more compact than Python lists. They are the foundation for scientific computing.
pynfinity 2025-04-18
📜
📜 List Comprehensions
List comprehensions provide a concise way to create lists.
santoshtvk 2024-11-17
🔍
🔍 Exploratory Data Analysis (EDA)
EDA is crucial for understanding your data. The `describe()` method gives you a quick statistical summary.
santoshtvk 2023-11-21
🧩
🧩 Python Regex Tutorial with Examples
Regular expressions (regex) in Python use the re module to search, match, and manipulate strings with powerful pattern rules.
santoshtvk 2027-01-29
📉
📉 Matplotlib Plotting
Matplotlib is the grandfather of Python visualization libraries. It gives you control over every aspect of a figure.
santoshtvk 2025-01-11
🎯
🎯 Python Common Interview Questions and Answers
Top Python interview questions asked at MNCs, and startups — with clear answers and code examples.
santoshtvk 2025-12-18
🚀
🚀 Streamlit Apps
Streamlit turns data scripts into shareable web apps in minutes. All in pure Python.
pynfinity 2027-11-01
λ
λ Python Lambda Functions — Small Anonymous Functions
Lambda functions are compact, one-line anonymous functions. Perfect for short operations passed to sort(), filter(), and map().
santoshtvk 2026-10-06
📅
📅 Python datetime Module — Working with Dates and Times
Python's datetime module handles dates, times, timezones, and arithmetic. Essential for logs, scheduling, and data pipelines.
santoshtvk 2026-02-20
✨ Jupyter Magic Commands
Magic commands are special commands that you can run in Jupyter notebooks to perform special tasks.
santoshtvk 2026-01-01
🗄️
🗄️ SQLAlchemy Basics
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power of SQL.
pynfinity 2027-09-12
🛠️
🛠️ Functools
The functools module is for higher-order functions: functions that act on or return other functions.
pynfinity 2024-02-20
🚪
🚪 Python Context Managers — The with Statement Explained
Context managers ensure resources (files, DB connections, locks) are always properly cleaned up, even when exceptions occur.
santoshtvk 2026-01-04
🧹
🧹 Data Cleaning with Dropna
Missing data is a common problem. Pandas provides `dropna()` to easily remove rows or columns with null values.
santoshtvk 2023-07-17
🌐
🌐 How to Use the requests Library in Python
The requests library is the go-to tool for making HTTP requests in Python. GET data from APIs, POST forms, handle auth — all in a few lines.
santoshtvk 2024-07-02
🕸️
🕸️ Web Scraping with BeautifulSoup
BeautifulSoup helps you parse HTML and extract the data you need from websites.
pynfinity 2028-03-12
🕸️
🕸️ Web Scraping with BeautifulSoup
BeautifulSoup helps you parse HTML and extract the data you need from websites.
pynfinity 2026-01-01
📊
📊 Interactive Plots with Plotly
Plotly allows you to create interactive charts that you can zoom, pan, and hover over.
santoshtvk 2026-01-01
📝
📝 Python logging Module — Proper Application Logging
Real applications need structured logs, not print() statements. Python's logging module provides levels, formatting, and file logging.
santoshtvk 2026-12-11
🔁
🔁 Itertools
This module implements a number of iterator building blocks inspired by constructs from APL, Haskell, and SML.
santoshtvk 2024-08-17
🔄
🔄 Python enumerate() and zip() — Cleaner Loop Patterns
enumerate() adds automatic counters to loops; zip() iterates multiple sequences together. Both eliminate messy manual indexing.
santoshtvk 2026-05-05
🥒
🥒 Pickle Serialization
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
pynfinity 2025-08-07
λ
λ Lambda Functions
A lambda function is a small anonymous function. It can take any number of arguments, but can only have one expression.
santoshtvk 2028-03-25
🏗️
🏗️ Python OOP — Classes, Objects, and Inheritance
Object-Oriented Programming in Python uses classes to bundle data and behaviour together. Master classes, inheritance, and dunder methods.
santoshtvk 2026-12-26
🤖
🤖 Scikit-Learn Linear Regression
Linear Regression is the 'Hello World' of Machine Learning. Scikit-Learn makes it a breeze to implement.
pynfinity 2027-07-19
⚔️
⚔️ FastAPI vs Flask — Which Should You Choose?
FastAPI and Flask are two of Python's most popular web frameworks. Here's a clear side-by-side comparison with real code examples.
santoshtvk 2024-01-15
📝
📝 NLTK Tokenization
Tokenization is the first step in NLP. It breaks text down into words or sentences.
santoshtvk 2025-04-06
📊
📊 CSV Processing
The csv module implements classes to read and write tabular data in CSV format.
santoshtvk 2023-06-14
🧠
🧠 TensorFlow Basics
TensorFlow is a powerful library for numerical computation and large-scale machine learning.
santoshtvk 2027-12-16
🔥
🔥 PyTorch Tensors
PyTorch tensors are similar to NumPy arrays but can run on GPUs for accelerated computing.
pynfinity 2027-06-12
💻
💻 Argparse CLI
The argparse module makes it easy to write user-friendly command-line interfaces.
santoshtvk 2023-02-04
🧪
🧪 Pytest Testing
Pytest is a framework that makes building simple and scalable tests easy.
santoshtvk 2025-10-19
🔍
🔍 Exploratory Data Analysis (EDA)
EDA is crucial for understanding your data. The `describe()` method gives you a quick statistical summary.
santoshtvk 2026-01-01
⚡ Python List Comprehension Examples
List comprehensions are Python's elegant one-liner loops. Write cleaner, faster code with this powerful feature.
santoshtvk 2026-11-12
🛡️
🛡️ Python Error Handling — try, except, finally Explained
Proper exception handling makes your Python code robust and production-ready. Learn try/except/finally with real-world patterns.
santoshtvk 2026-06-14
✍️
Write a New Post
💎

Bits — Quick Code Snippets

🗺️ Folium Maps
🗺️ Folium Maps
📦 Dataclasses
📦 Dataclasses
🔁 Itertools
🔁 Itertools
🗄️ SQLAlchemy Basics
🗄️ SQLAlchemy Basics
📄 JSON Handling
📄 JSON Handling
🖥️ OS Module
🖥️ OS Module
🔢 NumPy Arrays
🔢 NumPy Arrays
⚡ Generators
⚡ Generators
🐼 Pandas DataFrames
🐼 Pandas DataFrames
🎛️ Multiprocessing
🎛️ Multiprocessing
⚡ FastAPI Endpoints
⚡ FastAPI Endpoints
📜 List Comprehensions
📜 List Comprehensions
🪵 Logging
🪵 Logging
🚀 Streamlit Apps
🚀 Streamlit Apps
🧪 Pytest Testing
🧪 Pytest Testing
🧠 TensorFlow Basics
🧠 TensorFlow Basics
🌲 Git Basics
🌲 Git Basics
📦 Virtual Environments
📦 Virtual Environments
🏷️ Type Hinting
🏷️ Type Hinting
🚪 Context Managers
🚪 Context Managers
🛠️ Functools
🛠️ Functools
🧩 Regular Expressions
🧩 Regular Expressions
🎀 Decorators
🎀 Decorators
📸 OpenCV Image Reading
📸 OpenCV Image Reading
💻 Argparse CLI
💻 Argparse CLI
🛡️ Pydantic Models
🛡️ Pydantic Models
📚 Collections Module
📚 Collections Module
📝 NLTK Tokenization
📝 NLTK Tokenization
📉 Matplotlib Plotting
📉 Matplotlib Plotting
🔥 Seaborn Heatmaps
🔥 Seaborn Heatmaps
🧵 Multithreading
🧵 Multithreading
⏳ AsyncIO
⏳ AsyncIO
🔥 PyTorch Tensors
🔥 PyTorch Tensors
⚙️ Sys Module
⚙️ Sys Module
☁️ AWS S3 with Boto3
☁️ AWS S3 with Boto3
🥒 Pickle Serialization
🥒 Pickle Serialization
🕸️ NetworkX Graphs
🕸️ NetworkX Graphs
➗ Math Module
➗ Math Module
λ Lambda Functions
λ Lambda Functions
📊 CSV Processing
📊 CSV Processing
🐳 Dockerfiles
🐳 Dockerfiles
📉 Statsmodels OLS
📉 Statsmodels OLS
+ New Post
By pynfinity | 2024-12-18 06:57:09

➗ Math Module

This module provides access to the mathematical functions defined by the C standard.

💡 Quick Tip:

Mastering this concept will significantly boost your Python data science skills!

💻 Code Example:

import math

# 1. Basic operations
print("π          :", math.pi)
print("e          :", math.e)
print("√2         :", math.sqrt(2))
print("2¹⁰        :", math.pow(2, 10))
print("log10(1000):", math.log10(1000))       # 3.0
print("ln(e²)     :", math.log(math.e**2))    # 2.0
print("log2(8)    :", math.log2(8))            # 3.0

# 2. Ceiling, floor, rounding
score = 87.654
print(f"\n{score} →  ceil={math.ceil(score)} | floor={math.floor(score)}")
print("gcd(48,36):", math.gcd(48, 36))
print("lcm(12, 8):", math.lcm(12, 8))

# 3. Trigonometry (in radians)
angle_deg = 45
angle_rad = math.radians(angle_deg)
print(f"\nsin(45°) = {math.sin(angle_rad):.4f}")
print(f"cos(45°) = {math.cos(angle_rad):.4f}")
print(f"tan(45°) = {math.tan(angle_rad):.4f}")
print(f"Reverse: {math.degrees(math.asin(math.sqrt(2)/2)):.1f}°")

# 4. Infinity and NaN handling
inf = math.inf
nan = math.nan
print(f"\nInfinity: {inf} | Is inf: {math.isinf(inf)}")
print(f"NaN:      {nan} | Is NaN: {math.isnan(nan)}")
print(f"Is finite(-1e308): {math.isfinite(-1e308)}")

# 5. Practical — compound interest calculator
def compound_interest(principal, rate_pct, years, n=12):
    r = rate_pct / 100
    amount = principal * (1 + r / n) ** (n * years)
    return round(amount, 2)

amount = compound_interest(10000, 8.5, 5)
print(f"\nPynfinity savings: ₹10,000 @ 8.5% for 5 yrs → ₹{amount:,}")

# 6. Special functions
print(f"\nfactorial(10): {math.factorial(10):,}")    # 3,628,800
print(f"hypot(3,4):    {math.hypot(3, 4)}")           # 5.0
print(f"comb(10,3):    {math.comb(10, 3)}")           # 120
print(f"perm(5,2):     {math.perm(5, 2)}")            # 20

Keep exploring and happy coding! 💻



Pynfinity
Install Pynfinity Add to home screen for the best experience