Python Strings – Part 1

A colourful cartoon-style landscape illustration shows festive bunting strung across the top, with triangular flags spelling out “Python Strings” in bright, playful letters. The background is light and cheerful, giving a fun and welcoming atmosphere.

A string is a way of representing text in Python. It could be a word, a sentence, or even a single character. Strings are always written inside quotes so Python knows it’s text and not code.

Examples:

Notice that "12345" is different from the number 12345. The first one is a string (text), while the second one is a number (integer).

You can use either single quotes ('...') or double quotes ("...") to make a string. Both work the same — you just need to make sure the opening and closing quote match.

Try this

  • Print your name using single quotes.
  • Print your favourite food using double quotes.
  • Try printing "12345" (as a string) and then 12345 (as a number). Can you see the difference?

Printing strings

The print() function shows text on the screen. Think of it as a way of telling Python: “Display this for me.”

You can also print more than one piece of text at once by separating them with commas:

Python automatically adds spaces between the different items when you use commas.

Try this

  • Print "Python is fun" to the screen.
  • Print "I love", "pizza", and "chips" in one line using commas.
  • Try printing the same three words joined together without commas: print("I love" "pizza" "chips"). What happens?

Joining strings (concatenation)

You can join strings together using the + symbol. This is called concatenation (joining).

Example:

This prints:

Hello World

Notice we added " " (a space inside quotes) to make sure the two words didn’t get squashed together.

You can join more than two strings together:

Try this

  1. Make two variables: first_name = "Alice" last_name = "Smith"
  2. Join them together to print your full name.
  3. Try adding a space between them.

Length of a string

Python can tell you how many characters are in a string using the built-in len() function. Characters include letters, numbers, spaces, and punctuation.

Each letter is counted, starting from the first P all the way to the last n.

Spaces and punctuation also count:

Try this

  • Make a string with your favourite animal, e.g. "elephant".
  • Use len() to find out how many letters it has.
  • Try adding a space to the string, e.g. "elephant animal". What happens to the length?

Accessing characters by position

Strings are like a row of characters in order. Each character has a position, called an index. In Python, the first position is 0, not 1.

Example with "Python":

To get a character, use square brackets [ ] with its position:

If you try to use a position that doesn’t exist, Python will give an IndexError. For example, "Python" has 6 characters, so the highest index you can use is 5.

Try this

  • Create fruit = "apple".
  • Print the first letter.
  • Print the last letter. (Hint: the last position is 4 because "apple" has 5 letters.)
  • Try printing fruit[10]. What error do you get?

Summary

  • A string is text inside quotes.
  • Use print() to show strings on screen.
  • Join strings together with +.
  • Use len() to count characters.
  • Access letters by their position (starting at 0) with [ ].

✅ With just these basics, you can already start writing small Python programs that work with text.

Main Topic

Python Fundamentals

A colourful cartoon-style landscape illustration shows a person sitting at a computer terminal, looking overwhelmed by the amount of information on the screen. Papers and symbols float around them, representing different programming concepts. The word “Fundamentals” is clearly written above the scene, highlighting the focus on beginner Python basics.

Beginner’s guide to Python fundamentals: strings, numbers, booleans, syntax, and text manipulation explained simply and clearly.

Other Tutorials in this Topic

A playful cartoon-style landscape illustration shows a large elephant on the left and a small cat on the right. Between them, a bold greater than ( > ) symbol points toward the cat, representing a Python comparison operator in a fun way.

Python Operators

Beginner’s guide to Python operators: arithmetic, comparison, logical, assignment, membership, and identity explained with examples.

A colourful cartoon-style landscape illustration shows a smiling robot holding up two placards: one clearly labelled True and the other False. The background is bright and cheerful, symbolising the concept of Boolean values in Python programming.

Python Booleans

Learn Python Booleans: True or False values, comparisons, logic operators, and decision-making with simple examples.

ChatGPT said: A colourful cartoon-style landscape illustration shows two large labelled containers: one marked Integers filled with whole numbers like 7, 0, and -3, and another marked Floats filled with decimal numbers like 3.14, -0.5, and 2.0. A cheerful character is sorting the numbers into the correct containers, visually explaining the difference between integers and floating-point numbers in Python.

Python Numbers

Learn Python numbers: integers and floats, arithmetic operations, conversions, rounding, precision issues, and practical exercises for beginners…

A colourful cartoon-style landscape illustration shows the text “python ” written across the scene. Above the gap, a labelled box with the word “strings” is tilted, pouring its contents into the space, visually representing a variable being used to fill in a placeholder.

Python Strings – Part 4

Discover Python string formatting: use f-strings, .format(), and number formatting to neatly combine variables and text into…

A colourful cartoon-style landscape illustration shows the words “python strings” in lowercase being fed into a large whimsical machine. On the other side, the text emerges transformed into “PYTHON STRINGS” in uppercase letters, symbolising string methods like .upper(). The machine has gears and pipes, giving a fun and playful feel.

Python Strings – Part 3

Learn Python string methods: change case, remove spaces, replace text, split and join words, and check content…

A digital landscape illustration shows a beige fabric banner with the words “Python Strings” written across it. The material is ripped down the centre, with large visible stitches crudely sewing the two halves back together, symbolising fixing or escaping characters in strings. The background is simple and muted, drawing attention to the torn fabric.

Python Strings – Part 2

Explore Python strings further: escape characters, multi-line strings, and slicing to extract parts of text, with simple…

A colourful cartoon-style illustration shows a confused student with orange hair shrugging in front of a computer screen. The screen displays a Python function with a missing indentation error:

Python Syntax

Learn Python syntax basics with clear examples and beginner-friendly practice exercises.

A cartoon-style illustration shows a person’s hands typing on a laptop running Visual Studio Code in dark mode. The screen displays a Python file with the code print("Hello, world!"), alongside a large, colourful Python logo. The background is bright blue, creating a vibrant and engaging learning atmosphere.

Start Coding Python with VS Code

Beginner’s guide to installing Python, setting up VS Code, and getting ready for coding.

Python Variables

Python Variables

Learn Python variables with simple explanations, real-world analogies, practice tasks to build confidence using data in programs.