Welcome! You've completed expressions, conditionals, and loops. Now you'll learn STRINGS in detail.

This guide gives you:

  1. What a string is (sequence of characters)
  2. Why strings matter (words, sentences, text – used everywhere)
  3. What you'll learn next: operators on strings, and string methods (built-in functions)
  4. A few simple examples to get you ready

Let’s go! πŸš€


Part 1: What is a String?

πŸ“Œ A string is a SEQUENCE OF CHARACTERS (letters, digits, spaces, symbols).

  • Used for: words, sentences, paragraphs, any text.
  • In Python you write it in quotes: "Hello" or 'Hello' or '''Hello'''.

Examples:

  • "Hi"
  • "Python"
  • "I am learning Python."
  • "123" ← this is a string (text), not the number 123

Part 2: You've Already Used Strings

πŸ“Œ You've already used strings in:

  • print("Hello") β†’ the message in quotes is a string
  • input("Enter number:") β†’ the prompt is a string
  • for x in "Hello": β†’ looping over each character

Python has a built-in STRING CLASS with many useful operations and methods. In the next lectures you'll learn them in detail.


Part 3: What You'll Learn – Operators

πŸ“Œ Operators that work on strings (you'll see them in detail soon):

  • + (concatenation): "Hello" + " " + "World" β†’ "Hello World"
  • * (repeat): "ab" * 3 β†’ "ababab"
  • in / not in: "e" in "Hello" β†’ True
  • Indexing: "Hello"[0] β†’ "H", "Hello"[1] β†’ "e"
  • Slicing: "Hello"[1:4] β†’ "ell"

These help you build and inspect text.

Quick demo:

print("   'Hi' + '!' =", "Hi" + "!")
print("   'x' * 4 =", "x" * 4)
print("   'e' in 'Hello' =", "e" in "Hello")

Part 4: What You'll Learn – Methods

πŸ“Œ The string CLASS has many METHODS (functions that work on that string).

Examples (you'll learn these properly in later lectures):

  • s.upper() β†’ convert to uppercase
  • s.lower() β†’ convert to lowercase
  • s.strip() β†’ remove spaces from sides
  • s.replace("old", "new")
  • s.split() β†’ split into a list of words
  • s.find("sub") β†’ find position of a substring

These make it easy to process and change text in your programs.

Quick demo:

s = "  Hello World  "
print("   s =", repr(s))
print("   s.strip() =", repr(s.strip()))
print("   s.upper() =", s.upper())

Part 5: Why Spend Time on Strings?

πŸ“Œ Strings are one of the most used types in programming:

  • User input is often text (names, messages, filenames).
  • Output is often text (messages, reports, HTML).
  • Parsing files, URLs, and data often means working with strings.

Learning operators and methods well will make your programs much easier to write. Do the challenges in the coming lectures and practice a lot!


Part 6: Summary

βœ… String = sequence of characters (words, sentences, text). Written in quotes in Python.

βœ… You'll learn: operators (+, *, in, indexing, slicing) and string methods (upper, lower, strip, etc.).

βœ… Python has a built-in string class; use it to process text easily. Practice with the upcoming challenges!


Congratulations!

You now understand the basics of Strings in Python! πŸŽ‰

Key Takeaways:

  • Strings are sequences of characters
  • You've already been using them everywhere
  • Next: powerful operators and methods
  • Strings are everywhere in real programs

Next Steps:

  • Learn string operators in detail
  • Practice with methods (upper, strip, replace)
  • Start the upcoming string challenges