Understanding Strings in Python with Vani

🚀 Day 10 of My Python Learning Journey – Understanding Strings in Python 🐍 Strings are one of the most commonly used data types in Python. They are used to store text data like names, messages, addresses, and more. 🔹 What is a String? A string is a sequence of characters enclosed in: Single quotes → 'Hello' Double quotes → "Hello" Triple quotes → '''Hello''' or """Hello""" (for multi-line text) Python Copy code name = "Vani" message = 'Welcome to Python' 🔹 Key Features of Strings ✅ Strings are Immutable 👉 Once created, we cannot change the characters inside a string. Python Copy code text = "Python" # text[0] = "J" ❌ Error (Strings are immutable) ✅ Strings support Indexing Python Copy code word = "Python" print(word[0]) # P print(word[-1]) # n ✅ Strings support Slicing Python Copy code print(word[0:4]) # Pyth 🔹 Common String Methods Python Copy code text = "python learning" print(text.upper()) # PYTHON LEARNING print(text.lower()) # python learning print(text.title()) # Python Learning print(text.replace("python", "Java")) print(len(text)) # Length of string 🔹 String Concatenation Python Copy code first = "Hello" second = "World" print(first + " " + second) # Hello World 🎯 Why Strings are Important? Strings are used in: User input Displaying output Working with files Web development Data processing ✨ Day 10 Complete! Today I learned that strings are immutable, support indexing & slicing, and come with powerful built-in methods. #Python #100DaysOfCode #LearningJourney #Strings #Coding

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories