🐍 Python Strings for Beginners
📚 Table of Contents
- What is a String?
- Creating Strings
- Accessing String Characters
- String Slicing
- String Methods
- String Formatting
- Escape Characters
- Practice Examples
- FAQ
💡 Quick Tip
Strings are used to store text data. Always use quotes
(single or double) while creating strings.
⚠️ Common Mistakes
- Forgetting quotation marks.
- Using wrong index numbers.
- Trying to change individual characters.
✍️ By Roshni Code Charm
📅 July 2026 | ⏱️ 5 min read
🐍 What is a String?
A string is a sequence of characters used to store text in Python.
Strings are written inside single (' ') or double (" ") quotes.
Creating Strings
name = "Roshni"
course = 'BCA'
print(name)
🔤 Accessing String Characters
Each character in a string has an index number.
Index starts from 0.
text = "Python"
print(text[0])
print(text[3])
✂️ String Slicing
Slicing is used to get a part of a string.
language = "Python"
print(language[0:3])
✨ Common String Methods
- upper() - Converts text to uppercase
- lower() - Converts text to lowercase
- replace() - Replace text
- split() - Split string into parts
- strip() - Remove extra spaces
- len() - Find string length
Example of String Methods
name = "python"
print(name.upper())
print(name.replace("p","P"))
📝 String Formatting
name = "Roshni"
age = 18
print(f"My name is {name} and age is {age}")
🔤 Escape Characters
- \n - New line
- \t - Tab space
- \" - Double quote
🚀 Practice Example
message = "Hello Python"
print(message.upper())
print(len(message))
❓ Frequently Asked Questions
1. What is a string in Python?
A string is a collection of characters used to store text.
2. Can we change string characters?
No, strings are immutable in Python.
3. Which quotes are used for strings?
Single quotes (' ') and double quotes (" ") can be used.