Sitemap

Strings in Python: A Beginner-Friendly Guide 🐍
Strings are one of the most commonly used data types in Python. A string is a sequence of characters enclosed inside single quotes, double quotes, or triple quotes.

4 min readSep 8, 2026

⚡ TL;DR: A string is just text. Learn 5 things (index, slice, methods, f-strings, immutability) and you can handle text in any Python project.
🎯 What you will learn in this guide:

🔍 How to pick any character using indexes
✂️ How to cut out parts of text with slicing
🧰 5 must-know methods: upper, lower, strip, replace, split
🎨 How to build neat sentences with f-strings
⚠️ Why strings can never be changed in place
⏱️ Reading time: about 5 minutes. Every example is copy-paste ready.

📌 What is a String?
A string is used to store text or a collection of characters.

name = “Shrinath”
message = ‘Hello World’

print(name)
print(message)
Output:

Shrinath
Hello World
✏️ Creating Strings
Python provides different ways to create strings:

str1 = ‘Hello’
str2 = “Python”
str3 = “””This is
a multiline
string.”””
💡 Tip: Triple quotes are useful when you want to write strings across multiple lines.
🔍 Accessing Characters
Think of a string like a row of lockers. Each locker has a number, and the numbering starts from 0, not 1.

Each character in a string has an index. Python uses zero-based indexing, which means the first character has index 0.

word = “Python”

print(word[0])
print(word[2])
Output:

P
t
You can also use negative indexing:

print(word[-1])
Output:

n
✂️ String Slicing
Slicing is like cutting a piece of ribbon: you decide where to start and where to stop.

Slicing allows you to extract a portion of a string.

word = “Python”

print(word[0:3])
print(word[2:6])
Output:

Pyt
thon
📖 Syntax: string[start:end]
The end index is not included.
🧰 Common String Methods
Python provides many useful built-in string methods.

1. upper()
Converts the string to uppercase.

name = “python”
print(name.upper())
Output:

PYTHON
2. lower()
Converts the string to lowercase.

name = “PYTHON”
print(name.lower())
Output:

python
3. strip()
Removes unnecessary spaces from the beginning and end.

text = “ Hello Python “
print(text.strip())
Output:

Hello Python
4. replace()
Replaces one part of a string with another.

Get Shirsathshrinath’s stories in your inbox

Join Medium for free to get updates from this writer.

text = “I like Java”
print(text.replace(“Java”, “Python”))
Output:

I like Python
5. split()
Splits a string into a list.

text = “Python is easy”
print(text.split())
Output:

[‘Python’, ‘is’, ‘easy’]
🔥 Pro tip: Method names are easy to remember. They say exactly what they do: upper makes UPPER, lower makes lower, strip strips the extra spaces.
🔗 String Concatenation
We can join two or more strings using the + operator.

first_name = “Shrinath”
last_name = “Shirsath”

full_name = first_name + “ “ + last_name
print(full_name)
Output:

Shrinath Shirsath
🎨 String Formatting
F-strings are a simple and powerful way to insert variables into strings.

name = “Shrinath”
age = 22

print(f”My name is {name} and I am {age} years old.”)
Output:

My name is Shrinath and I am 22 years old.
💎 Pro tip: Prefer f-strings over + when mixing text and numbers. They are shorter, cleaner and need no str() conversion.
✅ Checking a String
You can check whether a word or character exists inside a string using in.

text = “Python is powerful”
print(“Python” in text)
Output:

True
⚠️ Important: Strings are Immutable
Strings in Python are immutable, which means their individual characters cannot be changed directly.
word = “Python”

# word[0] = “J” # This will cause an error
Instead, create a new string:

word = “Python”
word = “J” + word[1:]

print(word)
Output:

Jython
📋 Quick Cheat Sheet
Save this one. It covers almost everything above.

s[0] # first character
s[-1] # last character
s[a:b] # slice (b is excluded)
s.upper() # UPPERCASE
s.lower() # lowercase
s.strip() # remove outer spaces
s.replace(“a”, “b”)
s.split() # string to list
f”Hi {name}” # f-string
“x” in s # True or False
🧠 Mini Challenge
Try these in your head first, then check the answers below.

word = “Python”

print(word[-2])
print(word[1:4])
print(word.upper()[:2])
Answers:

o
yth
PY
Got all three right? You have understood strings. 👏

🌟 Key Takeaways
Indexing starts at 0, and -1 means the last character
Slicing never includes the end index
Methods return a new string, they do not change the old one
f-strings are the cleanest way to format text
Strings are immutable, so always build a new one
🏁 Conclusion
Strings are an essential part of Python programming. By understanding indexing, slicing, concatenation, formatting, and string methods, you can easily work with text in Python.

Once you become comfortable with strings, you will find them useful in almost every Python project, from simple programs to Data Science, Machine Learning, and Web Development.

Happy Coding! 🚀🐍

👏 If this helped you, clap and follow for more beginner-friendly Python guides.
💬 Which topic should come next: Lists, Dictionaries or Loops? Tell me in the comments.
more attractive :

Strings in Python: A Beginner-Friendly Guide