HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python Essentials
  3. /Text Processing

Text Processing

Python Programming · High School (9–10) · 2 courses, 26 worked problems, 30 practice questions

Much of the data in the world is text: messages, books, logs and web pages. Python stores text as strings and gives many tools to work with them. You can split a sentence into words with .split(), join words with .join(), change case with .lower(), and find or replace parts with .find() and .replace(). A loop and a dictionary can count how often each word appears. You can also clean messy input, check whether a word is a palindrome, make simple codes and read a whole text file.

With practice you will be able to

  • Split text into words and count how often each one appears
  • Clean and change text with string methods
  • Check a string for a pattern such as a palindrome

On the syllabus of

  • CBSE / State Class 12
  • Python Certification
  • A-Level

Lessons

  • Three Essentials ProjectsCan you crack a Caesar code without knowing the shift?High School (9–10)
  • Working with TextWhy are The, the and THE different words to Python? How does a secret code work?High School (9–10)

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

contacts = {"ravi": "98765"}. What does contacts.get("Ravi".lower()) give?

A message was coded with a shift of 19. Which shift, from 0 to 25, decodes it with the same function?

ranked = sorted([("Asha", 72), ("Ravi", 85), ("Meera", 64)], key=lambda p: -p[1]). What is ranked[0][0]?

commands = {"hi": greet}, where greet is a function. What does commands["hi"]() do?

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • Write three small functions square(n), double(n) and negate(n), and a dictionary operations that…Medium
  • Choose a project: a program that keeps the scores of a quiz game and shows who is winning…Easy
  • Write a function above_mean(marks) for a dictionary of name and mark…Medium
  • A line has the form name:mark, such as Asha:72…Medium
  • What kind of text?Easy
  • Write a function initials(name) that gives the capital initials of a name, so that "asha kumari…

Python labs

  • Contact book tools
  • Guess the shift
  • Marks report tools
  • Run the commands
  • Project: the command menu
  • Plan and test: a unit converter

Related topics

  • Python Essentials
  • Dictionaries
  • Tuples and Sets
  • Errors and Exceptions
  • Modules and Libraries
  • Searching and Sorting
  • Recursion
  • Essentials Projects

Splitting at a comma: what does print(len("a,b,,c".split(","))) show?

count() counts pieces that do not overlap. What does print("banana".count("an")) show?

A shift of 1 in the letter code: what is chr((ord("z") - ord("a") + 1) % 26 + ord("a"))?

What does print(" Hello World ".strip().lower()) show?

Why is a dictionary a good tool for a contact book?

What does contacts.get("zoya") give if there is no Zoya in the book?

All 30 practice questions on Text Processing →

Easy
  • Write add(name, number) for the contact book…Easy
  • The book has asha and ravi. What happens with contacts["zoya"]? …Easy
  • The book is {"meera": "99887", "asha": "98765", "ravi": "91234", "kabir": "90000"}…Medium
  • Count the letters of balloon with a dictionary…Medium
  • In a long English secret, the most common letter is x…Medium
  • The secret is mjqqt. The letter q appears twice, so the rule guesses that q stands for e…Hard
  • All 26 worked problems on Text Processing →