Skip to content
scipython.com

Q2.3.1String slicing

Slice the string s='seehemewe' to produce the following substrings:

(a) 'see'

(b) 'he'

(c) 'me'

(d) 'we'

(e) 'hem'

(f) 'meh'

(g) 'wee'

Show solution

Slice the string s='seehemewe' as follows (other solutions are possible in some cases):

(a) s[:3]

(b) s[3:5]

(c) s[5:7]

(d) s[7:]

(e) s[3:6]

(f) s[5:2:-1]

(g) s[-2::-3]