INFO

A sequence of characters used to represent text. It is one of the most fundamental data types in programming and is typically enclosed in quotes.

String

Properties

  • Immutable in many languages (e.g., Python, JavaScript), meaning once created, it cannot be changed
  • Indexed: each character has a position starting from 0
  • Can contain letters, digits, symbols, and whitespace
    • characters represented in ASCII

Common Operations

  • Concatenation: Combine two or more strings ("Hello" + "World""HelloWorld")
  • Substring: Extract part of a string ("Hello"[1:4]"ell")
  • Search: Find characters or patterns ("apple".find("p")1)
  • Replace: Substitute characters or substrings ("cat".replace("c", "b")"bat")
  • Length: Count number of characters (len("hello")5)