Interactive Code Snippets

Code examples for - Page 3

Run, edit, and experiment with ready-to-use code algorithms and utilities right in your browser.

Showing 24 templates
python

Python String title() Method: Capitalize Words

Learn how to use Python's title() method to convert first letter of each word to uppercase and remaining letters to lowercase with examples.

Run
python

Convert Decimal to Hexadecimal in Python

Learn how to use the built-in hex() function in Python to convert decimal numbers to hexadecimal with code examples.

Run
python

How to Add an Item to a Python Dictionary with update()

Learn how to add a key-value pair to a Python dict using the update() method. Example included.

Run
PHP

Display City Temperatures & Find Hottest with PHP

PHP code to sort cities by name, display temperatures, and find the hottest city with detailed explanation.

Run
python

Print Odd Numbers in Python (Handling Negatives)

Learn how to print odd numbers in Python for both positive and negative inputs. Simple function with example.

Run
python

Difference of Squares in Python | Math Challenge

Python code to compute the difference between the square of sum and sum of squares for numbers 1 to 100. Ideal for math challenges and coding practice.

Run
python

Python all() Function with Data Types

Learn how to use Python's all() function with lists, sets, and dictionaries through practical examples and output analysis.

Run
python

Draw a Fish with Stars in Python – ASCII Pattern

See how this Python snippet draws a star-pattern fish with nested loops. Eye, mouth and tail explained, plus how to run and customize the code.

Run
PHP

PHP Person Class Example: Set Name, Get Name

Learn how to define a PHP class with private property, setter, and getter methods. Simple example of using a Person object.

Run
python

Python Recursive Factorial Function Example

Learn how to calculate factorial in Python using a recursive function. See the code, output 720, usage notes, and limitations for 0 or negative input.

Run
python

Convert Numbers to Words in Python with num2words

Learn how to convert numbers to words in Python using the num2words library, including Persian text, ordinals and currency output.

Run
python

Draw a Diamond Pattern in Python (Nested Loops)

Learn how to draw a diamond (rhombus) star pattern in Python using for and while loops. Full code explained line by line with sample output.

Run
python

Compare Two Dictionaries in Python with == and !=

Learn how to compare two dictionaries in Python using == and !=, check equal keys and values, ignore order, and see practical code examples.

Run
python

Convert Two Lists to a Dictionary in Python (zip)

Learn how to convert two lists into a dictionary in Python with zip() and dict() — a fast, Pythonic way to map keys to values.

Run
python

Convert Dictionary to List in Python

Learn how to convert dictionary keys and values to lists in Python using keys() and values() methods.

Run
python

Reverse a String in Python Using Slicing

Learn how to reverse a string in Python using slicing. Simple code example with step-by-step explanation.

Run
python

Sort DataFrame with pandas | Python sort_values Tutorial

Learn how to sort a pandas DataFrame using the sort_values method with practical Python examples.

Run
python

Calculate Sum of DataFrame Columns in Pandas

Learn how to calculate the sum of numeric columns in a pandas DataFrame using sum() in Python.

Run
PHP

PHP Image Upload with Validation and Security Checks

Learn how to validate image uploads in PHP with extension, size, and MIME type checks before moving files securely to a server directory.

Run
python

Python Triangle Number Pattern: Nested Loop

This Python code prints a right-angled number triangle based on user input using nested loops. Perfect for beginners learning loops.

Run
python

Python Fibonacci Sequence Generator with User Input

Generate Fibonacci series up to N terms in Python. Simple script with input validation and while loop.

Run
python

Python Pyramid Pattern with Numbers

Learn how to print a number pyramid pattern in Python using nested loops. Simple and clean code example.

Run
python

Sort List of Dictionaries by Value in Python

Learn how to sort a list of dictionaries by a specific key in Python using the sort() method with a custom key function.

Run
python

Python Email Validation using Regex

Learn how to validate email addresses in Python using regex. This script checks a list of emails and prints valid/invalid with colors.

Run