๐ 20 Python Programming Examples for Beginners (With Code)
Are you looking for easy and practical Python programming examples for beginners? Whether youโre a student just starting out or someone looking to sharpen their coding skills, this post has everything you need to start coding in Python with confidence.
In this beginner-friendly guide
youโll find 20 simple Python examples with code that cover basic concepts and common programming problems. These examples are perfect for daily practice and help you build a strong foundation in Python.
โ Why Practice Python Programming as a Beginner?
- Understand syntax and logic step by step.
- Boost confidence through hands-on problem-solving.
- Prepare for exams, interviews, or projects.
These beginner-level Python examples cover all of that, with clean, short, and working code.
๐ฐ What You Need
Before you begin, make sure youโve:
- Installed Python on your PC or using an online compiler like Replit
- Learned basic concepts: variables, loops, functions, and conditions.
๐ If not, check out our Learn Python in 30 Days series before jumping into these examples.
๐ง 20 Python Programming Examples for Beginners
- Print โHello, World!โ
print("Hello, World!")
- Add Two Numbers
a = 10 b = 5 print("Sum:", a + b)
- Check Even or Odd
num = int(input("Enter a number: ")) if num % 2 == 0: print("Even") else: print("Odd")
- Swap Two Variables
x = 5 y = 10 x, y = y, x print("x =", x, "y =", y)
- Find the Largest of Three Numbers
a, b, c = 10, 20, 15 print("Largest:", max(a, b, c))
- Check Leap Year
year = int(input("Enter year: ")) if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0): print("Leap Year") else: print("Not a Leap Year")
- Factorial of a Number
def factorial(n): result = 1 for i in range(1, n+1): result *= i return result print(factorial(5))
- Fibonacci Series
a, b = 0, 1 for _ in range(10): print(a, end=" ") a, b = b, a + b
- Check Prime Number
n = int(input("Enter number: ")) is_prime = True if n < 2: is_prime = False for i in range(2, int(n**0.5)+1): if n % i == 0: is_prime = False break print("Prime" if is_prime else "Not Prime")
- Reverse a String
s = "Python" print(s[::-1])
- Palindrome Check
word = input("Enter word: ") print("Palindrome" if word == word[::-1] else "Not Palindrome")
- Simple Calculator
a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print("Add:", a + b) print("Subtract:", a - b) print("Multiply:", a * b) print("Divide:", a / b)
- Count Vowels in a String
s = "hello world" vowels = "aeiou" count = sum(1 for char in s if char.lower() in vowels) print("Vowels:", count)
- Print a Pattern
for i in range(1, 6): print("*" * i)
- Check Armstrong Number
n = int(input("Enter number: ")) order = len(str(n)) sum = sum(int(digit) ** order for digit in str(n)) print("Armstrong" if sum == n else "Not Armstrong")
- List Sum
nums = [5, 10, 15, 20] print("Sum:", sum(nums))
- Find Duplicates in List
lst = [1, 2, 2, 3, 4, 4, 5] duplicates = set([x for x in lst if lst.count(x) > 1]) print("Duplicates:", duplicates)
- Create a Dictionary
student = {"name": "John", "age": 15, "grade": "10th"} print(student)
- Convert Celsius to Fahrenheit
c = float(input("Enter Celsius: ")) f = (c * 9/5) + 32 print("Fahrenheit:", f)
- Guess the Number Game
import random num = random.randint(1, 10) guess = int(input("Guess the number (1-10): ")) print("Correct!" if guess == num else f"Wrong! It was {num}")
๐ Final Thoughts
These 20 Python programming examples for beginners are designed to give you real practice and confidence. Try modifying each program, experiment with the inputs, and challenge yourself to go deeper.
โ Bookmark this post and use it as your daily Python workout!
๐ Next Steps
If you found this helpful, explore more:
Learn Python in 30 Days (Complete Guide)