Now, let's move to the next topic in the Python Coding Challenge:
Strings & String Methods
A string is a sequence of characters inside quotes. You can use:
name = "Alice"
greeting = 'Hello!'
paragraph = """This is
a multiline string."""
π Strings are immutable β once created, they can't be changed directly.
β¨ Common String Methods
Here are some useful methods youβll use all the time:
lower() β makes everything lowercase
upper() β makes everything uppercase
strip() β removes spaces from start and end
replace("old", "new") β replaces parts of a string
split() β splits text into a list of words
count("word") β counts how many times something appears
find("word") β finds the position of a word
startswith("Hello") β checks how a string begins
endswith("world") β checks how a string ends
π§ͺ Examples
msg = " Python is Awesome! "
print(msg.lower()) # python is awesome!
print(msg.strip()) # Python is Awesome!
print(msg.replace("Awesome", "Powerful")) # Python is Powerful!
print(msg.split()) # ['Python', 'is', 'Awesome!']
π Project 1: Word Counter
text = input("Enter a sentence: ")
words = text.split()
print("Word count:", len(words))
Try it with:
> Python is easy and powerful
β Output: 5
π Project 2: Palindrome Checker
text = input("Enter a word: ")
if text == text[::-1]:
print("Palindrome!")
else:
print("Not a palindrome.")
Try:
- madam β Palindrome
- racecar β Palindrome
- hello β Not a palindrome
React with β€οΈ once youβre ready for the quiz
Strings & String Methods
A string is a sequence of characters inside quotes. You can use:
name = "Alice"
greeting = 'Hello!'
paragraph = """This is
a multiline string."""
π Strings are immutable β once created, they can't be changed directly.
β¨ Common String Methods
Here are some useful methods youβll use all the time:
lower() β makes everything lowercase
upper() β makes everything uppercase
strip() β removes spaces from start and end
replace("old", "new") β replaces parts of a string
split() β splits text into a list of words
count("word") β counts how many times something appears
find("word") β finds the position of a word
startswith("Hello") β checks how a string begins
endswith("world") β checks how a string ends
π§ͺ Examples
msg = " Python is Awesome! "
print(msg.lower()) # python is awesome!
print(msg.strip()) # Python is Awesome!
print(msg.replace("Awesome", "Powerful")) # Python is Powerful!
print(msg.split()) # ['Python', 'is', 'Awesome!']
π Project 1: Word Counter
text = input("Enter a sentence: ")
words = text.split()
print("Word count:", len(words))
Try it with:
> Python is easy and powerful
β Output: 5
π Project 2: Palindrome Checker
text = input("Enter a word: ")
if text == text[::-1]:
print("Palindrome!")
else:
print("Not a palindrome.")
Try:
- madam β Palindrome
- racecar β Palindrome
- hello β Not a palindrome
React with β€οΈ once youβre ready for the quiz
β€2
what is the output of the following code ?
msg = " Learn Python " print(msg.strip())
msg = " Learn Python " print(msg.strip())
Anonymous Quiz
26%
" Learn Python "
32%
"Learn Python"
42%
"LearnPython"
0%
" Learn Python"
β€2
Q2. Which method is used to turn all characters in a string to uppercase?
Anonymous Quiz
9%
capital()
55%
upper()
15%
toupper()
21%
uppercase()
β€2
what is the result of this code?
text = " Python Programming " print(text.split())
text = " Python Programming " print(text.split())
Anonymous Quiz
56%
['Python', 'Programming']
29%
['P','y','t','h','o','n'']
6%
['PythonProgramming']
9%
['Python_Programming']
β€2
Q4. Which of these strings is a palindrome?
Anonymous Quiz
70%
"racecar"
20%
"Python"
10%
"banana"
0%
"hello"
β€2
what does this result ?
"hello".replace("l","*")
"hello".replace("l","*")
Anonymous Quiz
29%
he*lo
62%
he**o
10%
he*o
0%
h**lo
β€3
Now, Let's move to the next topic in the Python Coding Challenge:
Lists & Tuples
πΉ What is a List?
A list is a mutable (changeable) collection of items in a specific order.
Syntax:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
fruits.append("mango")
print(fruits) # Output: ['apple', 'banana', 'cherry', 'mango']
β You can add, remove, or update elements in a list.
πΈ What is a Tuple?
A tuple is similar to a list, but it's immutable (unchangeable once defined).
Syntax:
colors = ("red", "green", "blue")
print(colors[1]) # Output: green
π You cannot modify, append, or remove elements from a tuple after creation.
β Key Differences:
Mutability:
- List: Mutable β you can change, add, or remove elements after creation.
- Tuple: Immutable β once defined, you cannot change, add, or remove elements.
Syntax:
- List: Use square brackets β []
my_list = [1, 2, 3]
- Tuple: Use round brackets β ()
my_tuple = (1, 2, 3)
Use Case:
- List: Use when you need to modify the collection later.
- Tuple: Use when the data should remain constant or to ensure integrity.
Performance:
Tuple is slightly faster than List due to immutability and fixed size.
π Mini Project: Grocery List Manager
Letβs build a simple grocery list app where you can:
- Add items
- Remove items
- Display all items
Python Code:
grocery_list = []
while True:
print("\nOptions: add / remove / show / exit")
action = input("What would you like to do? ")
if action == "add":
item = input("Enter item to add: ")
grocery_list.append(item)
print(f"{item} added.")
elif action == "remove":
item = input("Enter item to remove: ")
if item in grocery_list:
grocery_list.remove(item)
print(f"{item} removed.")
else:
print("Item not found.")
elif action == "show":
print("Your grocery list:")
for i in grocery_list:
print("-", i)
elif action == "exit":
break
else:
print("Invalid option.")
β Try running this and see how lists work in real time!
React with β€οΈ once youβre ready for the quiz
Lists & Tuples
πΉ What is a List?
A list is a mutable (changeable) collection of items in a specific order.
Syntax:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
fruits.append("mango")
print(fruits) # Output: ['apple', 'banana', 'cherry', 'mango']
β You can add, remove, or update elements in a list.
πΈ What is a Tuple?
A tuple is similar to a list, but it's immutable (unchangeable once defined).
Syntax:
colors = ("red", "green", "blue")
print(colors[1]) # Output: green
π You cannot modify, append, or remove elements from a tuple after creation.
β Key Differences:
Mutability:
- List: Mutable β you can change, add, or remove elements after creation.
- Tuple: Immutable β once defined, you cannot change, add, or remove elements.
Syntax:
- List: Use square brackets β []
my_list = [1, 2, 3]
- Tuple: Use round brackets β ()
my_tuple = (1, 2, 3)
Use Case:
- List: Use when you need to modify the collection later.
- Tuple: Use when the data should remain constant or to ensure integrity.
Performance:
Tuple is slightly faster than List due to immutability and fixed size.
π Mini Project: Grocery List Manager
Letβs build a simple grocery list app where you can:
- Add items
- Remove items
- Display all items
Python Code:
grocery_list = []
while True:
print("\nOptions: add / remove / show / exit")
action = input("What would you like to do? ")
if action == "add":
item = input("Enter item to add: ")
grocery_list.append(item)
print(f"{item} added.")
elif action == "remove":
item = input("Enter item to remove: ")
if item in grocery_list:
grocery_list.remove(item)
print(f"{item} removed.")
else:
print("Item not found.")
elif action == "show":
print("Your grocery list:")
for i in grocery_list:
print("-", i)
elif action == "exit":
break
else:
print("Invalid option.")
β Try running this and see how lists work in real time!
React with β€οΈ once youβre ready for the quiz
β€1
what is the output of the following code ?
fruits = ["apple","banana","cherry"]
print(fruits[1])
fruits = ["apple","banana","cherry"]
print(fruits[1])
Anonymous Quiz
29%
apple
64%
banana
4%
cherry
4%
None of the above
β€1
Q2. Which of these defines a tuple correctly?
Anonymous Quiz
32%
my_tuple = [1,2,3]
54%
my_tuple = (1,2,3)
14%
my_tuple = {1,2,3}
β€1
Which operation is not allowed on a tuple?
Anonymous Quiz
12%
Accessing an item
20%
iteration over the items
52%
Appending an item
16%
Checking length
β€1
What is the main difference between a list and a tuple?
Anonymous Quiz
24%
List is immutable, tuple is mutable
0%
Tuple allows duplicate values, list does not
76%
List is mutable, tuple is immutable
β€1
β€1
Today, let's move on to the next topic in the Python Coding Challenge:
Dictionaries & Sets ππ§Ί
πΉDay 5: What is a Dictionary in Python?
A dictionary is an unordered, mutable collection that stores data in key-value pairs.
π§ Example:
student = {
"name": "Amit",
"age": 21,
"course": "Python"
}
print(student["name"]) # Output: Amit
- Keys must be unique and immutable (like strings, numbers).
- Values can be anything: strings, numbers, lists, or even other dictionaries.
π§° Common Dictionary Methods:
student.get("age") # Returns 21
student.keys() # Returns all keys
student.values() # Returns all values
student.items() # Returns key-value pairs
student["grade"] = "A+" # Adds a new key-value pair
πΉ What is a Set in Python?
A set is an unordered collection of unique elements.
π§ Example :
numbers = {1, 2, 3, 4, 4, 2}
print(numbers) # Output: {1, 2, 3, 4} β no duplicates
- Sets remove duplicates automatically.
- Useful for membership checks, uniqueness, and set operations (union, intersection).
β Real-Life Project: Contact Book using Dictionary
- Build a CLI-based contact book where users can:
- Add new contacts (name, phone)
- View all contacts
- Search by name
- Delete a contact
π‘ Python Code:
contacts = {}
while True:
print("\n1. Add Contact\n2. View All\n3. Search\n4. Delete\n5. Exit")
choice = input("Enter choice: ")
if choice == '1':
name = input("Name: ")
phone = input("Phone: ")
contacts[name] = phone
print("Contact saved!")
elif choice == '2':
for name, phone in contacts.items():
print(f"{name} : {phone}")
elif choice == '3':
name = input("Enter name to search: ")
if name in contacts:
print(f"{name}'s phone: {contacts[name]}")
else:
print("Contact not found.")
elif choice == '4':
name = input("Enter name to delete: ")
if name in contacts:
del contacts[name]
print("Deleted successfully.")
else:
print("No such contact.")
elif choice == '5':
break
else:
print("Invalid choice.")
React with β€οΈ once youβre ready for the quiz
Dictionaries & Sets ππ§Ί
πΉDay 5: What is a Dictionary in Python?
A dictionary is an unordered, mutable collection that stores data in key-value pairs.
π§ Example:
student = {
"name": "Amit",
"age": 21,
"course": "Python"
}
print(student["name"]) # Output: Amit
- Keys must be unique and immutable (like strings, numbers).
- Values can be anything: strings, numbers, lists, or even other dictionaries.
π§° Common Dictionary Methods:
student.get("age") # Returns 21
student.keys() # Returns all keys
student.values() # Returns all values
student.items() # Returns key-value pairs
student["grade"] = "A+" # Adds a new key-value pair
πΉ What is a Set in Python?
A set is an unordered collection of unique elements.
π§ Example :
numbers = {1, 2, 3, 4, 4, 2}
print(numbers) # Output: {1, 2, 3, 4} β no duplicates
- Sets remove duplicates automatically.
- Useful for membership checks, uniqueness, and set operations (union, intersection).
β Real-Life Project: Contact Book using Dictionary
- Build a CLI-based contact book where users can:
- Add new contacts (name, phone)
- View all contacts
- Search by name
- Delete a contact
π‘ Python Code:
contacts = {}
while True:
print("\n1. Add Contact\n2. View All\n3. Search\n4. Delete\n5. Exit")
choice = input("Enter choice: ")
if choice == '1':
name = input("Name: ")
phone = input("Phone: ")
contacts[name] = phone
print("Contact saved!")
elif choice == '2':
for name, phone in contacts.items():
print(f"{name} : {phone}")
elif choice == '3':
name = input("Enter name to search: ")
if name in contacts:
print(f"{name}'s phone: {contacts[name]}")
else:
print("Contact not found.")
elif choice == '4':
name = input("Enter name to delete: ")
if name in contacts:
del contacts[name]
print("Deleted successfully.")
else:
print("No such contact.")
elif choice == '5':
break
else:
print("Invalid choice.")
React with β€οΈ once youβre ready for the quiz
β€2
What will be the output of following code?
d = {"a": 1, "b": 2} print(d.get("c"))
d = {"a": 1, "b": 2} print(d.get("c"))
Anonymous Quiz
10%
0
29%
Error
27%
None
34%
"c"
β€1
Which one of these is NOT allowed as a key in a dictionary?
Anonymous Quiz
21%
integer
17%
String
48%
Tuple
14%
List
β€2
Which method returns all key-value pairs in a dictionary?
Anonymous Quiz
32%
.Values()
17%
.get()
27%
.items()
24%
.keys()
β€1
What will this code output?
info = {"name": "Alex", "age": 25} info["city"] = "New York" print("info")
info = {"name": "Alex", "age": 25} info["city"] = "New York" print("info")
Anonymous Quiz
44%
{'name': 'Alex', 'age': 25, 'city': 'New York'}
21%
{'city': 'New York'}
17%
info
19%
Error
β€1
What will be the output of this code ?
s = {1,2,3,2,4}
print(len(s))
s = {1,2,3,2,4}
print(len(s))
Anonymous Quiz
62%
5
27%
4
9%
3
2%
2
β€2
Today, Letβs move on to the next topic in the Python Coding Challenge:
πΉDay 6: Conditionals (if, elif, else)
In Python, conditional statements allow your code to make decisions.
π‘ What Are Conditionals?
They help your program execute certain code blocks only when specific conditions are true.
β Syntax :
if condition:
# Code runs if condition is True
elif another_condition:
# Runs if previous conditions were False, this one is True
else:
# Runs if none of the above conditions are True
π§ Example :
age = 18
if age >= 18:
print("Youβre an adult.")
elif age > 13:
print("Youβre a teenager.")
else:
print("Youβre a child.")
Output:
Youβre an adult.
π― Mini Project: Guess the Number Game
Letβs build a small game using what weβve learned so far:
Python Code
import random
number = random.randint(1, 10)
guess = int(input("Guess a number between 1 and 10: "))
if guess == number:
print("π Correct! You guessed it right.")
elif guess < number:
print("Too low! Try again.")
else:
print("Too high! Try again.")
print(f"The correct number was: {number}")
This project uses:
- if, elif, else
- User input
- Random module
React with β€οΈ once youβre ready for the quiz
πΉDay 6: Conditionals (if, elif, else)
In Python, conditional statements allow your code to make decisions.
π‘ What Are Conditionals?
They help your program execute certain code blocks only when specific conditions are true.
β Syntax :
if condition:
# Code runs if condition is True
elif another_condition:
# Runs if previous conditions were False, this one is True
else:
# Runs if none of the above conditions are True
π§ Example :
age = 18
if age >= 18:
print("Youβre an adult.")
elif age > 13:
print("Youβre a teenager.")
else:
print("Youβre a child.")
Output:
Youβre an adult.
π― Mini Project: Guess the Number Game
Letβs build a small game using what weβve learned so far:
Python Code
import random
number = random.randint(1, 10)
guess = int(input("Guess a number between 1 and 10: "))
if guess == number:
print("π Correct! You guessed it right.")
elif guess < number:
print("Too low! Try again.")
else:
print("Too high! Try again.")
print(f"The correct number was: {number}")
This project uses:
- if, elif, else
- User input
- Random module
React with β€οΈ once youβre ready for the quiz
β€6
Today, let's start with the first topic in Python Programming Roadmap:
β Python Programming Basics ππ»
π Step 1: Install Python & VS Code
* Download Python 3.11+ from python.org
* During install, check β Add Python to PATH
* Install VS Code
* In VS Code, install the Python extension
To check:
Open terminal β Type: python --version
You should see something like: Python 3.x.x
π Step 2: Your First Python Program
Create a file: hello.py
Paste this code:
print("Hello, Python")
Run it in terminal: python hello.py
π§ Python runs code top to bottom
π¨ print() displays output on the screen
π Step 3: Variables
Variables store values.
age = 25
name = "Deepak"
height = 5.11
print(age, name, height)
βοΈ No need to declare types β Python figures it out
βοΈ Use lowercase names with underscores
π Step 4: Data Types
* int β Whole numbers (e.g., 10)
* float β Decimals (e.g., 3.14)
* str β Text (e.g., "hello")
* bool β True / False
To check type:
x = 10
print(type(x))
π Step 5: Input & Output
Take input from user:
python
name = input("Enter your name: ")
print("Hello", name)
Convert string input to number:
age = int(input("Enter age: "))
print("Next year you'll be", age + 1)
π Step 6: Arithmetic Operators
a = 10
b = 3
print(a + b) # Add
print(a - b) # Subtract
print(a * b) # Multiply
print(a / b) # Divide
print(a // b) # Floor division
print(a % b) # Remainder
π Step 7: String Operations
first = "Data"
second = "Analyst"
print(first + " " + second) # Concatenate
print("Hi " * 3) # Repeat
print(len(first)) # Length
π Step 8: Practice Programs
1οΈβ£ Simple Calculator
β Input 2 numbers, show sum, difference, product, division
2οΈβ£ Temperature Converter
β Input Celsius, convert to Fahrenheit
F = (C * 9/5) + 32
3οΈβ£ Age After 5 Years
β Input current age, print age after 5 years
Here is the detailed code for each project:
π Project 1. Simple Calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Addition:", num1 + num2)
print("Subtraction:", num1 - num2)
print("Multiplication:", num1 * num2)
if num2 != 0:
print("Division:", num1 / num2)
else:
print("Division not possible")
π Project 2. Temperature Converter (Celsius to Fahrenheit)
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
π Project 3. Age After 5 Years
age = int(input("Enter your age: "))
future_age = age + 5
print("Your age after 5 years:", future_age)
π Bonus Practice β Area of a Rectangle
length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
print("Area of rectangle:", area)
π‘Useful Tips
* Run each program
* Change input values
* Break it on purpose and fix it
π§ Daily Rule:
* Code at least 60 mins
* Type every line manually
* Donβt copy-paste β build muscle memory
I have decided to give some quizzes after this post to test your knowledge
β Python Programming Basics ππ»
π Step 1: Install Python & VS Code
* Download Python 3.11+ from python.org
* During install, check β Add Python to PATH
* Install VS Code
* In VS Code, install the Python extension
To check:
Open terminal β Type: python --version
You should see something like: Python 3.x.x
π Step 2: Your First Python Program
Create a file: hello.py
Paste this code:
print("Hello, Python")
Run it in terminal: python hello.py
π§ Python runs code top to bottom
π¨ print() displays output on the screen
π Step 3: Variables
Variables store values.
age = 25
name = "Deepak"
height = 5.11
print(age, name, height)
βοΈ No need to declare types β Python figures it out
βοΈ Use lowercase names with underscores
π Step 4: Data Types
* int β Whole numbers (e.g., 10)
* float β Decimals (e.g., 3.14)
* str β Text (e.g., "hello")
* bool β True / False
To check type:
x = 10
print(type(x))
π Step 5: Input & Output
Take input from user:
python
name = input("Enter your name: ")
print("Hello", name)
Convert string input to number:
age = int(input("Enter age: "))
print("Next year you'll be", age + 1)
π Step 6: Arithmetic Operators
a = 10
b = 3
print(a + b) # Add
print(a - b) # Subtract
print(a * b) # Multiply
print(a / b) # Divide
print(a // b) # Floor division
print(a % b) # Remainder
π Step 7: String Operations
first = "Data"
second = "Analyst"
print(first + " " + second) # Concatenate
print("Hi " * 3) # Repeat
print(len(first)) # Length
π Step 8: Practice Programs
1οΈβ£ Simple Calculator
β Input 2 numbers, show sum, difference, product, division
2οΈβ£ Temperature Converter
β Input Celsius, convert to Fahrenheit
F = (C * 9/5) + 32
3οΈβ£ Age After 5 Years
β Input current age, print age after 5 years
Here is the detailed code for each project:
π Project 1. Simple Calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Addition:", num1 + num2)
print("Subtraction:", num1 - num2)
print("Multiplication:", num1 * num2)
if num2 != 0:
print("Division:", num1 / num2)
else:
print("Division not possible")
π Project 2. Temperature Converter (Celsius to Fahrenheit)
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print("Temperature in Fahrenheit:", fahrenheit)
π Project 3. Age After 5 Years
age = int(input("Enter your age: "))
future_age = age + 5
print("Your age after 5 years:", future_age)
π Bonus Practice β Area of a Rectangle
length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
print("Area of rectangle:", area)
π‘Useful Tips
* Run each program
* Change input values
* Break it on purpose and fix it
π§ Daily Rule:
* Code at least 60 mins
* Type every line manually
* Donβt copy-paste β build muscle memory
I have decided to give some quizzes after this post to test your knowledge
β€2
β€1