Python Basics

Course by zooboole,

Last Updated on 2025-02-26 16:14:49

Introduction

What Are Strings?

A string in Python is a sequence of characters enclosed in single ('), double ("), or triple quotes (''' or """). Strings are widely used to store and manipulate text data.

Examples of Strings:

# Using single quotes
name = 'John Doe'

# Using double quotes
greeting = "Hello, World!"

# Using triple quotes (for multi-line strings)
paragraph = '''This is a 
multi-line string in Python.'''

Key Characteristics of Strings:

  • Strings are immutable, meaning they cannot be changed after creation.
  • Strings can contain letters, numbers, spaces, and special characters.
  • Python provides many methods for manipulating strings, which we will explore in later lessons.

Why Use Strings?

Strings are essential in almost every programming task, including:

  • Storing and manipulating user input
  • Displaying messages and interacting with users.
  • Processing textual data (e.g., names, emails, file paths)

In the upcoming lessons, we will explore string manipulation techniques, indexing, slicing(kind of cutting), operations, and methods that make handling text data powerful and efficient in Python.


Quick Exercise: Think About It!

  1. What is the difference between using single quotes and double quotes for strings in Python?
  2. What will be the output of print("It's a great day!")?
  3. How do you create a multi-line string?

Get ready to dive deeper into working with strings in the next lesson!