The best way to learn Python is by practicing examples. This page contains examples on basic concepts of Python. We encourage you to try these examples on your own before looking at the solution.
Table of Contents
Introduction
- Python Program to Print Hello world!
- Python Program to Print Output Without a Newline
- Python Program to Convert Celsius To Fahrenheit
- Python Program to Convert Kilometers to Miles
- Python Program to Generate a Random Number
- Python Program to Swap Two Variables
- Python Program to Solve Quadratic Equation
- Python Program to Calculate the Area of a Triangle
- Python Program to Find the Square Root
- Python Program to Add Two Numbers
Advanced
- Python Program to Measure the Elapsed Time in Python
- Python Program to Convert Bytes to a String
- Python Program to Create a Countdown Timer
- Python Program to Represent enum
Object Oriented
- Python Program to Get the Class Name of an Instance
- Python Program to Differentiate Between type() and isinstance()
Decision Making and Loops
- Python Program to Check if a Number is Positive, Negative or 0
- Python Program to Compute the Power of a Number
- Python Program to Reverse a Number
- Python Program to Iterate Over Dictionaries Using for Loop
- Python Program to Create Pyramid Patterns
- Python Program to Find the Sum of Natural Numbers
- Python Program to Find Armstrong Number in an Interval
- Python Program to Check Armstrong Number
- Python Program to Print the Fibonacci sequence
- Python Program to Display the multiplication Table
- Python Program to Find the Factorial of a Number
- Python Program to Print all Prime Numbers in an Interval
- Python Program to Check Prime Number
- Python Program to Find the Largest Among Three Numbers
- Python Program to Check Leap Year
- Python Program to Check if a Number is Odd or Even
Functions
- Python Program to Display Powers of 2 Using Anonymous Function
- Python Program to Return Multiple Values From a Function
- Python Program to Convert Decimal to Binary Using Recursion
- Python Program to Find Factorial of Number Using Recursion
- Python Program to Find Sum of Natural Numbers Using Recursion
- Python Program to Display Fibonacci Sequence Using Recursion
- Python Program to Display Calendar
- Python Program to Shuffle Deck of Cards
- Python Program to Make a Simple Calculator
- Python Program to Find the Factors of a Number
- Python Program to Find LCM
- Python Program to Find HCF or GCD
- Python Program to Find ASCII Value of Character
- Python Program to Convert Decimal to Binary, Octal and Hexadecimal
- Python Program to Find Numbers Divisible by Another Number
Native Datatypes
- Python Program to Remove Duplicate Element From a List
- Python Program to Count the Number of Occurrence of a Character in String
- Python Program to Compute all the Permutation of the String
- Python Program to Capitalize the First Character of a String
- Python Program to Check If Two Strings are Anagram
- Python Program to Count the Number of Digits Present In a Number
- Python Program to Iterate Through Two Lists in Parallel
- Python Program to Trim Whitespace From a String
- Python Program to Convert Two Lists Into a Dictionary
- Python Program to Create a Long Multiline String
- Python Program to Delete an Element From a Dictionary
- Python Program to Count the Occurrence of an Item in a List
- Python Program to Check If a String Is a Number (Float)
- Python Program to Randomly Select an Element From the List
- Python Program to Get a Substring of a String
- Python Program to Get the Last Element of the List
- Python Program to Convert String to Datetime
- Python Program to Print Colored Text to the Terminal
- Python Program to Parse a String to a Float or Int
- Python Program to Split a List Into Evenly Sized Chunks
- Python Program to Check if a Key is Already Present in a Dictionary
- Python Program to Concatenate Two Lists
- Python Program to Check If a List is Empty
- Python Program to Sort a Dictionary by Value
- Python Program to Slice Lists
- Python Program to Flatten a Nested List
- Python Program to Access Index of a List Using for Loop
- Python Program to Merge Two Dictionaries
- Python Program to Count the Number of Each Vowel
- Python Program to Illustrate Different Set Operations
- Python Program to Sort Words in Alphabetic Order
- Python Program to Remove Punctuations From a String
- Python Program to Check Whether a String is Palindrome or Not
- Python Program to Multiply Two Matrices
- Python Program to Transpose a Matrix
- Python Program to Add Two Matrices
Files
- Python Program to Check the File Size
- Python Program to Get the Full Path of the Current Working Directory
- Python Program to Get File Creation and Modification Date
- Python Program to Find All File with .txt Extension Present Inside a Directory
- Python Program to Get Line Count of a File
- Python Program to Get the File Name From the File Path
- Python Program to Extract Extension From the File Name
- Python Program to Append to a File
- Python Program Read a File Line by Line Into a List
- Python Program to Copy a File
- Python Program to Catch Multiple Exceptions in One Line
- Python Program to Safely Create a Nested Directory
- Python Program to Find Hash of File
- Python Program to Find the Size (Resolution) of a Image
- Python Program to Merge Mails