Ravindra BagaleCourses & study guides मराठी Track your progress

Python Strings Tutorial: Slicing, f-strings and String Methods with Examples

Ravindra Bagale's Tip — Chala mitrano

Names, cities, product codes, email IDs — most raw data is text. Today we learn to cut, clean and format text. These same methods come back in pandas as .str methods.

What you will learn in this chapter

  • How to create strings and join them
  • Indexing and slicing to cut parts of text
  • Cleaning methods: strip, lower, upper, replace
  • split and join for lists of words
  • f-strings to format money and messages
  • How to check text with in, startswith and endswith

Practice data

All names, shops, banks, hospitals and amounts in this chapter are made up for learning. They are not real people or real company numbers.

Concepts in this chapter

  1. P3.1How to Create and Join Strings in Python
  2. P3.2Python String Indexing and Slicing Explained
  3. P3.3Python String Methods: strip, lower, upper, replace, split
  4. P3.4Python f-strings: Format Numbers, Money and Percentages
  5. P3.5How to Check Text with in, startswith and endswith