Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

PY
Python
0/14 completed
Beginner
Hello PythonVariables and typesWorking with stringsConditions and loopsFunctions
Intermediate
Lists, tuples, dicts and setsFiles and exceptionsModules and the standard library
Advanced
Classes and OOPIterators and generatorsDecorators and context managers
Pro
Async PythonTesting and type hintsVirtual environments, packages and real projects
Tracks / Python / Beginner

Working with strings

Text is everywhere: names, messages, files, web pages. Python's strings (str) come with dozens of useful built-in tools.

Creating strings

Python · editable

f-strings: building text from values

Python · editable

Indexing and slicing

A string is a sequence of characters, numbered from 0. Negative numbers count from the end:

 P  y  t  h  o  n
 0  1  2  3  4  5
-6 -5 -4 -3 -2 -1
Python · editable

Strings are immutable: you can't change a character in place. Methods return a new string:

Python · editable
Python · editable

Useful string methods

Python · editable

Splitting and joining

split breaks a string into a list; join glues a list back together:

Python · editable

Checking for text

Python · editable

Looping over characters

Python · editable

A small program: initials and a username

Python · editable

Practice

  1. Ask for a sentence (Input box) and print how many words it has, and the longest word. (Hint: max(words, key=len).)
  2. Turn "2025-03-14" into "14/03/2025" using split and an f-string.
  3. Print a word reversed and in upper case.
Python · editable
✎ Check your understanding

1.What does "Python"[1:4] give?

2.What does "a,b,c".split(",") return?

3.Why does word[0] = "J" fail?

← Variables and types