MWZ

MINDWAREZONE

What is String

  • A string is a sequence of characters used to represent text.
  • Strings can contain letters, numbers, symbols, spaces, and emojis.
  • Strings are enclosed in single quotes ('), double quotes ("), or triple quotes (''' or """).
  • Strings are one of the most commonly used data types in Python.
  • Each character in a string has an index position starting from 0.
  • Strings are immutable, meaning their contents cannot be changed after creation.
  • Python supports Unicode strings, allowing text from different languages and symbols.
  • Strings can be combined using the + operator (concatenation).
  • Strings can be repeated using the * operator.
  • Many built-in methods are available for string manipulation, such as upper(), lower(), and replace().

Examples

Example 1: Creating a String

name = "Alice"
print(name)
            

Output:

Alice
            

Example 2: String with Numbers and Symbols

message = "Order #123"
print(message)
            

Output:

Order #123
            

Example 3: Unicode String

greeting = "नमस्ते"
print(greeting)
            

Output:

नमस्ते
            

Example 4: Accessing Characters

text = "Python"
print(text[0])
print(text[1])
            

Output:

P
y