Python Concatenate Strings
String manipulation is helpful for:
- Cleaning the dataset to prepare it for text mining or sentiment analysis.
- Process email content to feed a machine learning algorithm which decides whether an email is spam.
- Parse and extract specific data from a website to build a database.
my_string = "This is a string" my_string2 = 'This is also a string'
You can find the length of the string using the
my_string = "Awesome day" len(my_string)
A palindrome is a sequence of characters which can be read the same backward as forward, for example:
no melon. You realize that there are some funny movie names that can have this characteristic. You want to make a list of all movie titles that are funny palindromes but you will start by analyzing one example.
In python, you can also specify steps by using a third index. If you don't specify the first or second index and the third one is negative, it will return the characters jumping and backwards.
TRY IT YOURSELF: Access the exercise in our Regular Expressions in Python course here.
- Extract the substring from the 12th to the 30th character from the variable movie which corresponds to the
movietitle. Store it in the variable
- Get the palindrome by reversing the string contained in
- Complete the code to print out the
movie_titleif it is a palindrome.
# Get the word movie_title = ____[____] # Obtain the palindrome palindrome = ____[____] # Print the word if it's a palindrome if movie_title == palindrome: print(____)
To learn more about string manipulation, please see this video from our course Regular Expressions in Python.