
15.6K
FLWhat is a String in Python?
• A string is a sequence of characters.
• Written inside single quotes, double quotes, or triple quotes.
Examples:
"Python"
'Hello World'
"""This is a string"""
How Python Stores Strings (Important Concept)
Internally, Python stores a string as:
• A sequence (array) of characters
• Each character has an index
Example:
"PYTHON"
Index 0 1 2 3 4 5
Char P Y T H O N
So you can access characters using indexing:
• First character → index 0
• Last character → index -1
Why Strings are Immutable in Python (Very Important)
🔒 Meaning of Immutable
Immutable means:
Once a string is created, it cannot be changed.
What You CANNOT Do
name = "Python"
name [0] = "J" # ❌ Error
Python does not allow this.
✅ What Actually Happens
name = "Python"
name = "Jython"
• Old string "Python" is not modified
• A new string "Jython" is created
• Variable name now points to the new string
4️⃣ String Operations (Core Concepts)
➕ Concatenation (Joining)
"Hello" + "World" # HelloWorld
🔁 Repetition
"Hi" * 3 # HiHiHi
🔍 Membership
"a" in "apple" # True
📏 Length
len("Python") # 6
Important String Functions (Must Know)
5 🔤 Case Conversion Functions
upper() – Convert to uppercase
text = "python"
text.upper()
✅ Output: "PYTHON"
🧠 Use case: Display usernames in CAPS, headings
lower() – Convert to lowercase
email = "NAGA@GMAIL.COM"
email.lower()
✅ Output: "naga@gmail.com"
🧠 Use case: Email comparison (emails are case-insensitive)
6 title() – First letter of every word capital
name = "naga balla"
name.title()
✅ Output: "Naga Balla"
🧠 Use case: Names, headings
capitalize() – Only first character capital
msg = "hello world"
msg.capitalize()
✅ Output: "Hello world"
🧠 Use case: Sentence formatting
swapcase() – Upper ↔ Lower
text = "PyThOn"
text.swapcase()
✅ Output: "pYtHoN"
🧠 Use case: Text transformations, fun effects
✂️ Trimming Functions (Very Common)
strip() – Remove spaces (both sides)
name = " Naga "
name.strip()
✅ Output: "Naga"
🧠 Use case: User input cleaning
To explain more the description space is not sufficient so join our WhatsApp channel link in bio there will be pdf
#code #python #programming #30dayschallenge #telugu
@flashcoders_










