Slice a string in python (right, left, mid equivalents)


import pandas as pd

Create some dummy data

string = '8754321'
string
'8754321'
#right 2 characters
string[-2:]
'21'
#left 2 characters
string[:2]
'87'
#4th through 6th characters (index starts at 0)
string[4:6]
'32'


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.