Python Tutorial in Hindi #5 - Basic Operations, Slicing & Functions

Python Strings Explained with Examples | Basic Operations, Slicing & Functions | Mohit Decodes


In this Python tutorial, you’ll master the fundamentals of Python Strings — one of the most essential data types in programming. Whether you're just starting with Python or preparing for interviews, this video will help you strengthen your string handling skills with real examples and a mini challenge at the end.


✅ Topics Covered:

What are Strings in Python?

String Concatenation

String Length using len()

Indexing & Slicing

Useful String Methods (like upper(), lower(), replace(), find(), etc.)

Mini Challenge to test your learning


🎯 Perfect for beginners and intermediate learners preparing for Python interviews or building strong fundamentals.


# ---------------------------------------------
# Python Day 5 - Strings: Basic Operations, Slicing & Functions
# Mohit Decodes | Python Full Course in Hindi
# ---------------------------------------------

# ✅ 1️⃣ String Declaration
name = "Mohit Decodes"
language = 'Python Programming'

print(name)
print(language)
print(type(name)) # <class 'str'>

# ✅ 2️⃣ String Concatenation
full_text = name + " teaches " + language
print(full_text)

# ✅ 3️⃣ String Length
print("Length of name:", len(name))

# ✅ 4️⃣ Accessing Characters using Indexing
print(name[0]) # M
print(name[5]) # t
print(name[-1]) # s (last character)

# ✅ 5️⃣ String Slicing
print(name[0:5]) # Mohit
print(name[6:]) # Decodes
print(name[:6]) # Mohit (same as [0:6])
print(name[::2]) # MhtDcds (skip every 2nd char)
print(name[::-1]) # sesoced tih oM (reverse string)

# ✅ 6️⃣ Useful String Functions
text = " python programming language "

print("\nString Functions:")
print(text.upper()) # Uppercase
print(text.lower()) # Lowercase
print(text.title()) # Title Case
print(text.strip()) # Removes leading/trailing spaces
print(text.replace("python", "java")) # Replace word
print(text.find("gram")) # Find substring (returns index)

# ✅ 7️⃣ String Immutability
# Strings cannot be changed once created
greet = "Hello"
# greet[0] = "h" ❌ (Not allowed)
greet = "h" + greet[1:] # ✅ create new string
print(greet)

# ✅ 8️⃣ String with escape characters
sentence = "He said, \"Python is fun!\""
print(sentence)

# ✅ 9️⃣ Multi-line String
info = """This is
a multi-line
string in Python."""
print(info)

# ✅ 🔟 Mini Challenge 🧠
# Ask the user for their name, print uppercase version & character count

print("\n🧠 Mini Challenge 🧠")
user_name = input("Enter your name: ")
print("Your name in uppercase:", user_name.upper())
print("Your name length is:", len(user_name), "characters")