Title: String Indexing
Slug: string_indexing
Summary: String Indexing
Date: 2016-05-01 12:00
Category: Python
Tags: Basics
Authors: Chris Albon

Create a string


In [1]:
string = 'Strings are defined as ordered collections of characters.'

In [2]:
string[:]


Out[2]:
'Strings are defined as ordered collections of characters.'

In [3]:
string[0:3]


Out[3]:
'Str'

In [4]:
string[:3]


Out[4]:
'Str'

In [5]:
string[-3:]


Out[5]:
'rs.'

In [6]:
string[2:5]


Out[6]:
'rin'

In [7]:
string[0:10:2]


Out[7]:
'Srnsa'

In [8]:
string[::-1]


Out[8]:
'.sretcarahc fo snoitcelloc deredro sa denifed era sgnirtS'