Piyal Banik Profile picture
👨‍🎓 MSc Student in Data Science 🤖 Machine Learning Lead @gdsc_cdtu 🎯 My goal is to make your Data Science & Machine Learning Journey Easy

Jun 18, 2021, 8 tweets

Everything you need to know about Strings in Python for Data Science

Thread 🧵👇

#DataScience #Python #100daysofcodechallenge

📌Looping Through a String

Since strings are arrays, we can loop through the characters in a string, with a for loop.

📌String Length
To get the length of a string, use the len() function.

📌Check String
To check if a certain phrase or character is present in a string, we can use the keyword in.

📌Slicing

we can return a range of characters by using the slice syntax.
- Slice From the Start
- Slice To the End
- Negative Indexing

📌Modify Strings

Python has a set of built-in methods that we can use on strings.
- upper()
- lower()
- strip()
- replace()

📌String Concatenation

We can join two strings using the + operator

📌Format Strings

We can combine strings and numbers by using the format() method!

The format() method takes the passed arguments, formats them, and places them in the string where the placeholders {} are:

📌Additional Useful String Methods
- isalpha()
- isdigit()
- find()

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling