CodeSansar
  • Tutorials ▾
  • Examples ▾
  • Online Calculator
  • Tutorials ▾
  • Examples ▾
  • Online Calculator
  • Hello, World!
  • Add Two Numbers
  • Multiply Two Numbers
  • Celsius to Fahrenheit & Kelvin
  • Simple & Compound Interest
  • Rectangle Area & Perimeter
  • Area and Circumference of Circle
  • Calculate Area & Volume of Sphere
  • Area of Triangle
  • Area of an Ellipse
  • Area of Cone
  • Calculate Distance Between Two Points ( Co-ordinates)
  • Convert Cartesian to Polar Coordinate
  • Convert Polar to Cartesian Coordinate
  • Kilometer to Meter Conversion
  • Miles to Kilometers
  • Add Two Complex Number
  • Multiply Two Complex Number
  • Find Roots of a Quadratic Equation
  • Calculate Gravitational Force
  • Sum of First & Last Digit
  • Find ASCII Value
  • Days to Years, Months & Days Conversion
  • Calculate Monthly EMI
  • Check Leap Year
  • Even or Odd
  • Even or Odd Using Bitwise Operator
  • Even or Odd Using Conditional Operator
  • Largest of Two Numbers
  • Smallest of Two Numbers
  • Largest of Three Numbers
  • Smallest of Three Numbers
  • Calculate Value of PI Using Leibniz Formula
  • Validity of Triangle Given Sides
  • Validity of Triangle Given Angles
  • Check Triangle Types Given Sides
  • Python Program to Check Palindrome Number
  • Python Program to Check Prime Number
  • Python Program to Find Factorial of a Given Number
  • Python Program to Reverse a Given Number
  • Python Program to Calculate HCF (GCD) & LCM
  • Python Program to Calculate HCF (GCD) by Euclidean Algorithm
  • Python Program to Count Number of Digit
  • Python Program to Check Armstrong (Narcissistic) Number
  • Python Program to Check Whether a Number is Strong or Not
  • Python Program to Generate Fibonacci Series
  • Python Program to Check Perfect Number
  • Python Program to Check Triangular Number
  • Python Program to Check Co-Prime Numbers
  • Python Program to Check Automorphic (Cyclic) Number
  • Python Program to Generate Prime Numbers in Interval
  • Python Program to Generate Armstrong (Narcissistic) Number
  • Python Program to Generate Strong Numbers in an Interval
  • Python Program to Generate Perfect Numbers in an Interval
  • Generate Triangular Numbers in an Interval
  • Generate Automorphic (Cyclic) Numbers
  • Handsome Number Check
  • Harshad Number Check
  • Prime Factors
  • Powerful Number Check
  • Print Powerful Number in Range
  • Check Perfect Square
  • Divisors Of Given Number
  • Print Odd Numbers in Range
  • Print Even Numbers in Range
  • Multiplication Table of Number
  • Multiplication Table of 1 to 10
  • Types of Number
  • Sum of Digit of A Number
  • Sum of Digit of Number Until It Reduces To Single Digit
  • ASCII Table
  • Cartesian Product 2 Sets
  • Cartesian Product Multiple Sets
  • Generate Magic Square
  • Right Angle Triangle Star Pattern
  • Hollow Right Angle Triangle Pattern
  • Star Pyramid Pattern
  • Hollow Star Pyramid Pattern
  • Inverted Star Pyramid Pattern
  • 1-212-32123 Pattern
  • 1-121-12321 Pattern
  • Print 1-10-101-1010 Number Pattern
  • Print 0-01-010-0101 Binary Number Pattern
  • Print 1-101-10101 Binary Number Pyramid
  • Print 0-010-01010 Binary Number Pyramid
  • Flag of Nepal Using Star
  • Christmas Tree Pattern
  • Floyd's Triangle
  • Plus Star Pattern
  • Cross Star Pattern
  • Asterisk Like Pattern
  • Diamond Pattern
  • Hollow Diamond Pattern
  • Pascal's Triangle
  • Butterfly Pattern
  • 54321 5432 543 54 5 Pattern
  • 1 12 123 Pattern
  • 1 22 333 Pattern
  • a ab abc abcd Pattern
  • a bb ccc dddd pattern
  • A AB ABC ABCD Pattern
  • A BB CCC DDDD Pattern
  • A BAB CBABC Pattern
  • A ABA ABCBA Pattern
  • A ABC ABCDE Pattern
  • Hollow Square Pattern
  • Hollow Rectangular Pattern
  • Square Pattern
  • Rectangular Pattern
  • Hour-glass Pattern
  • Inverted Hollow Star Pyramid Pattern
  • Hollow Hour-glass Pattern
  • Plot Coordinates on a Plane
  • Sine Wave
  • Cos Wave
  • Sinc Function
  • Modified Bessel Function
  • Exponential Curve
  • Logarithmic Curve
  • Circle Plot
  • Heart Shape Plot
  • Plot Limacon
  • Plot Cardioid Curve
  • Plot Rose Curves
  • Plot Lemniscate Curve
  • Python Program to Find Factorial Using Recursive Function
  • Sum of Natural Numbers by Recursion
  • Sum of Digit of Number Recursion
  • Sum of 1-11-111 ... Using Recursion
  • nth term of Fibonacci series
  • Calculate Power Using Recursion
  • Calculate HCF (GCD) Using Recursive Function
  • Reverse Number Using Recursive Function
  • Longest Word in Sentence
  • Shortest Word in Sentence
  • Count Character Frequency in String
  • Highest Frequency Character in String
  • Lowest Frequency Character in String
  • Bitwise AND Operation Between Binary Strings
  • Bitwise OR Operation Between Binary Strings
  • Bitwise XOR Operation Between Binary Strings
  • Python One Line Code To Check Palindrome
  • Python One Line Code To Swap Two Numbers
  • Python One Line Code To Find Factorial (3 Methods)
  • Sorting Dictionary by Value in Python
  • Sorting Dictionary by Key in Python
  • Memory Address of Variables or Objects
  • Python Decorator to Measure Elapsed Time
  • Logging Decorator in Python
  • Memoization Decorator in Python
  • Simple Number Guessing Game in Python
  • Get Execution Time of Current Program
  • Get Current User of Computer
  • Monty Hall Game in Python
  • Ghost Game in Python
  • String to Binary Sequence
  • Collatz Conjecture Sequence Generator
  • Number to Words Conversion in Python (No Library Used)
  • Remove Duplicate Items From a Python List
  • How to count duplicate elements in Python list?
  • Check whether key exist in Python dictionary or not?
  • Python Floating Point Accuracy
  • Python Programming
  • C Programming
  • Numerical Methods
  • Dart Language
  • Computer Basics
  • Flutter
  • Linux
  • Deep Learning
  • Python Programming
  • C Programming
  • Numerical Methods
  • Dart Language
  • Computer Basics
  • Flutter
  • Linux
  • Deep Learning
  • C Programming Examples
  • Python Programming Examples
  • C Programming Examples
  • Python Programming Examples

Python Programming Examples

TOC ☵

  • Basic Programs
  • If & Loop
  • Pattern
  • Advance Programs
  • One Line Code
  • Python Recursion
  • Dictionary
  • Memory

Large collection of python programming examples with output to explain the concept of different python programming topics like decision making, loops, functions, list, tuple, dictionary, set, user defined function etc.


Basic Python Program Examples

  • Hello, World!
  • Add Two Numbers
  • Multiply Two Numbers
  • Celsius to Fahrenheit & Kelvin
  • Simple & Compound Interest
  • Rectangle Area & Perimeter
  • Area and Circumference of Circle
  • Calculate Area & Volume of Sphere
  • Area of Triangle
  • Area of an Ellipse
  • Area of Cone
  • Calculate Distance Between Two Points ( Co-ordinates)
  • Convert Cartesian to Polar Coordinate
  • Convert Polar to Cartesian Coordinate
  • Kilometer to Meter Conversion
  • Miles to Kilometers
  • Add Two Complex Number
  • Multiply Two Complex Number
  • Find Roots of a Quadratic Equation
  • Calculate Gravitational Force
  • Sum of First & Last Digit
  • Find ASCII Value
  • Days to Years, Months & Days Conversion
  • Calculate Monthly EMI

If-Else & Loop Examples

  • Check Leap Year
  • Even or Odd
  • Even or Odd Using Bitwise Operator
  • Even or Odd Using Conditional Operator
  • Largest of Two Numbers
  • Smallest of Two Numbers
  • Largest of Three Numbers
  • Smallest of Three Numbers
  • Calculate Value of PI Using Leibniz Formula
  • Validity of Triangle Given Sides
  • Validity of Triangle Given Angles
  • Check Triangle Types Given Sides
  • Python Program to Check Palindrome Number
  • Python Program to Check Prime Number
  • Python Program to Find Factorial of a Given Number
  • Python Program to Reverse a Given Number
  • Python Program to Calculate HCF (GCD) & LCM
  • Python Program to Calculate HCF (GCD) by Euclidean Algorithm
  • Python Program to Count Number of Digit
  • Python Program to Check Armstrong (Narcissistic) Number
  • Python Program to Check Whether a Number is Strong or Not
  • Python Program to Generate Fibonacci Series
  • Python Program to Check Perfect Number
  • Python Program to Check Triangular Number
  • Python Program to Check Co-Prime Numbers
  • Python Program to Check Automorphic (Cyclic) Number
  • Python Program to Generate Prime Numbers in Interval
  • Python Program to Generate Armstrong (Narcissistic) Number
  • Python Program to Generate Strong Numbers in an Interval
  • Python Program to Generate Perfect Numbers in an Interval
  • Generate Triangular Numbers in an Interval
  • Generate Automorphic (Cyclic) Numbers
  • Handsome Number Check
  • Harshad Number Check
  • Prime Factors
  • Powerful Number Check
  • Print Powerful Number in Range
  • Check Perfect Square
  • Divisors Of Given Number
  • Print Odd Numbers in Range
  • Print Even Numbers in Range
  • Multiplication Table of Number
  • Multiplication Table of 1 to 10
  • Types of Number
  • Sum of Digit of A Number
  • Sum of Digit of Number Until It Reduces To Single Digit
  • ASCII Table
  • Cartesian Product 2 Sets
  • Cartesian Product Multiple Sets
  • Generate Magic Square

Pattern Examples

  • Right Angle Triangle Star Pattern
  • Hollow Right Angle Triangle Pattern
  • Star Pyramid Pattern
  • Hollow Star Pyramid Pattern
  • Inverted Star Pyramid Pattern
  • 1-212-32123 Pattern
  • 1-121-12321 Pattern
  • Print 1-10-101-1010 Number Pattern
  • Print 0-01-010-0101 Binary Number Pattern
  • Print 1-101-10101 Binary Number Pyramid
  • Print 0-010-01010 Binary Number Pyramid
  • Flag of Nepal Using Star
  • Christmas Tree Pattern
  • Floyd's Triangle
  • Plus Star Pattern
  • Cross Star Pattern
  • Asterisk Like Pattern
  • Diamond Pattern
  • Hollow Diamond Pattern
  • Pascal's Triangle
  • Butterfly Pattern
  • 54321 5432 543 54 5 Pattern
  • 1 12 123 Pattern
  • 1 22 333 Pattern
  • a ab abc abcd Pattern
  • a bb ccc dddd pattern
  • A AB ABC ABCD Pattern
  • A BB CCC DDDD Pattern
  • A BAB CBABC Pattern
  • A ABA ABCBA Pattern
  • A ABC ABCDE Pattern
  • Hollow Square Pattern
  • Hollow Rectangular Pattern
  • Square Pattern
  • Rectangular Pattern
  • Hour-glass Pattern
  • Inverted Hollow Star Pyramid Pattern
  • Hollow Hour-glass Pattern

Matplotlib & Numpy

  • Plot Coordinates on a Plane
  • Sine Wave
  • Cos Wave
  • Sinc Function
  • Modified Bessel Function
  • Exponential Curve
  • Logarithmic Curve
  • Circle Plot
  • Heart Shape Plot
  • Plot Limacon
  • Plot Cardioid Curve
  • Plot Rose Curves
  • Plot Lemniscate Curve

Recursive Function Examples

  • Python Program to Find Factorial Using Recursive Function
  • Sum of Natural Numbers by Recursion
  • Sum of Digit of Number Recursion
  • Sum of 1-11-111 ... Using Recursion
  • nth term of Fibonacci series
  • Calculate Power Using Recursion
  • Calculate HCF (GCD) Using Recursive Function
  • Reverse Number Using Recursive Function

String Related

  • Longest Word in Sentence
  • Shortest Word in Sentence
  • Count Character Frequency in String
  • Highest Frequency Character in String
  • Lowest Frequency Character in String
  • Bitwise AND Operation Between Binary Strings
  • Bitwise OR Operation Between Binary Strings
  • Bitwise XOR Operation Between Binary Strings

One Line Code Examples

  • Python One Line Code To Check Palindrome
  • Python One Line Code To Swap Two Numbers
  • Python One Line Code To Find Factorial (3 Methods)

Dictionary Examples

  • Sorting Dictionary by Value in Python
  • Sorting Dictionary by Key in Python

Memory Related

  • Memory Address of Variables or Objects

Decorator

  • Python Decorator to Measure Elapsed Time
  • Logging Decorator in Python
  • Memoization Decorator in Python

Other Examples

  • Simple Number Guessing Game in Python
  • Get Execution Time of Current Program
  • Get Current User of Computer
  • Monty Hall Game in Python
  • Ghost Game in Python
  • String to Binary Sequence
  • Collatz Conjecture Sequence Generator
  • Number to Words Conversion in Python (No Library Used)
  • Remove Duplicate Items From a Python List
  • How to count duplicate elements in Python list?
  • Check whether key exist in Python dictionary or not?
  • Python Floating Point Accuracy
  • Basic Python Program Examples
    • Hello, World!
    • Add Two Numbers
    • Multiply Two Numbers
    • Celsius to Fahrenheit & Kelvin
    • Simple & Compound Interest
    • Rectangle Area & Perimeter
    • Area and Circumference of Circle
    • Calculate Area & Volume of Sphere
    • Area of Triangle
    • Area of an Ellipse
    • Area of Cone
    • Calculate Distance Between Two Points ( Co-ordinates)
    • Convert Cartesian to Polar Coordinate
    • Convert Polar to Cartesian Coordinate
    • Kilometer to Meter Conversion
    • Miles to Kilometers
    • Add Two Complex Number
    • Multiply Two Complex Number
    • Find Roots of a Quadratic Equation
    • Calculate Gravitational Force
    • Sum of First & Last Digit
    • Find ASCII Value
    • Days to Years, Months & Days Conversion
    • Calculate Monthly EMI
  • If-Else & Loop Examples
    • Check Leap Year
    • Even or Odd
    • Even or Odd Using Bitwise Operator
    • Even or Odd Using Conditional Operator
    • Largest of Two Numbers
    • Smallest of Two Numbers
    • Largest of Three Numbers
    • Smallest of Three Numbers
    • Calculate Value of PI Using Leibniz Formula
    • Validity of Triangle Given Sides
    • Validity of Triangle Given Angles
    • Check Triangle Types Given Sides
    • Python Program to Check Palindrome Number
    • Python Program to Check Prime Number
    • Python Program to Find Factorial of a Given Number
    • Python Program to Reverse a Given Number
    • Python Program to Calculate HCF (GCD) & LCM
    • Python Program to Calculate HCF (GCD) by Euclidean Algorithm
    • Python Program to Count Number of Digit
    • Python Program to Check Armstrong (Narcissistic) Number
    • Python Program to Check Whether a Number is Strong or Not
    • Python Program to Generate Fibonacci Series
    • Python Program to Check Perfect Number
    • Python Program to Check Triangular Number
    • Python Program to Check Co-Prime Numbers
    • Python Program to Check Automorphic (Cyclic) Number
    • Python Program to Generate Prime Numbers in Interval
    • Python Program to Generate Armstrong (Narcissistic) Number
    • Python Program to Generate Strong Numbers in an Interval
    • Python Program to Generate Perfect Numbers in an Interval
    • Generate Triangular Numbers in an Interval
    • Generate Automorphic (Cyclic) Numbers
    • Handsome Number Check
    • Harshad Number Check
    • Prime Factors
    • Powerful Number Check
    • Print Powerful Number in Range
    • Check Perfect Square
    • Divisors Of Given Number
    • Print Odd Numbers in Range
    • Print Even Numbers in Range
    • Multiplication Table of Number
    • Multiplication Table of 1 to 10
    • Types of Number
    • Sum of Digit of A Number
    • Sum of Digit of Number Until It Reduces To Single Digit
    • ASCII Table
    • Cartesian Product 2 Sets
    • Cartesian Product Multiple Sets
    • Generate Magic Square
  • Pattern Examples
    • Right Angle Triangle Star Pattern
    • Hollow Right Angle Triangle Pattern
    • Star Pyramid Pattern
    • Hollow Star Pyramid Pattern
    • Inverted Star Pyramid Pattern
    • 1-212-32123 Pattern
    • 1-121-12321 Pattern
    • Print 1-10-101-1010 Number Pattern
    • Print 0-01-010-0101 Binary Number Pattern
    • Print 1-101-10101 Binary Number Pyramid
    • Print 0-010-01010 Binary Number Pyramid
    • Flag of Nepal Using Star
    • Christmas Tree Pattern
    • Floyd's Triangle
    • Plus Star Pattern
    • Cross Star Pattern
    • Asterisk Like Pattern
    • Diamond Pattern
    • Hollow Diamond Pattern
    • Pascal's Triangle
    • Butterfly Pattern
    • 54321 5432 543 54 5 Pattern
    • 1 12 123 Pattern
    • 1 22 333 Pattern
    • a ab abc abcd Pattern
    • a bb ccc dddd pattern
    • A AB ABC ABCD Pattern
    • A BB CCC DDDD Pattern
    • A BAB CBABC Pattern
    • A ABA ABCBA Pattern
    • A ABC ABCDE Pattern
    • Hollow Square Pattern
    • Hollow Rectangular Pattern
    • Square Pattern
    • Rectangular Pattern
    • Hour-glass Pattern
    • Inverted Hollow Star Pyramid Pattern
    • Hollow Hour-glass Pattern
  • Matplotlib & Numpy
    • Plot Coordinates on a Plane
    • Sine Wave
    • Cos Wave
    • Sinc Function
    • Modified Bessel Function
    • Exponential Curve
    • Logarithmic Curve
    • Circle Plot
    • Heart Shape Plot
    • Plot Limacon
    • Plot Cardioid Curve
    • Plot Rose Curves
    • Plot Lemniscate Curve
  • Recursive Function Examples
    • Python Program to Find Factorial Using Recursive Function
    • Sum of Natural Numbers by Recursion
    • Sum of Digit of Number Recursion
    • Sum of 1-11-111 ... Using Recursion
    • nth term of Fibonacci series
    • Calculate Power Using Recursion
    • Calculate HCF (GCD) Using Recursive Function
    • Reverse Number Using Recursive Function
  • String Related
    • Longest Word in Sentence
    • Shortest Word in Sentence
    • Count Character Frequency in String
    • Highest Frequency Character in String
    • Lowest Frequency Character in String
    • Bitwise AND Operation Between Binary Strings
    • Bitwise OR Operation Between Binary Strings
    • Bitwise XOR Operation Between Binary Strings
  • One Line Code Examples
    • Python One Line Code To Check Palindrome
    • Python One Line Code To Swap Two Numbers
    • Python One Line Code To Find Factorial (3 Methods)
  • Dictionary Examples
    • Sorting Dictionary by Value in Python
    • Sorting Dictionary by Key in Python
  • Memory Related
    • Memory Address of Variables or Objects
  • Decorator
    • Python Decorator to Measure Elapsed Time
    • Logging Decorator in Python
    • Memoization Decorator in Python
  • Other Examples
    • Simple Number Guessing Game in Python
    • Get Execution Time of Current Program
    • Get Current User of Computer
    • Monty Hall Game in Python
    • Ghost Game in Python
    • String to Binary Sequence
    • Collatz Conjecture Sequence Generator
    • Number to Words Conversion in Python (No Library Used)
    • Remove Duplicate Items From a Python List
    • How to count duplicate elements in Python list?
    • Check whether key exist in Python dictionary or not?
    • Python Floating Point Accuracy
About Us

Codesansar is online platform that provides tutorials and examples on popular programming languages.

Links
  • About Us
  • Contact Us
  • Privacy Policy
  • Cookies Policy
Social Media
  • Facebook
  • Twitter
  • Youtube
  • Github
  • Instagram
© 2025 Codesansar. All Rights Reserved.