slicing string like slicing an apple:-using idle

 Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>> fruit="pomegranate"

>>> ##slicing

>>> ##string name[start,stop,step]

>>> fruit="pomegranate"

>>> ##by default start is '0', stop is 'n', step is '1'    by rght hand side:-start by default is -1, stop is 'n' and step is 1(remember this).

>>> fruit[1:2:3]

'o'

>>> fruit[0:11:3]

'peat'

>>> fruit[-1:6]

''

>>> fruit[-1:11:-1]

''

>>> fruit[-1:10:-1]

''

>>> fruit[-1::-1]

'etanargemop'

>>> fruit[::]

'pomegranate'

>>> fruit[-1:-11:-1]

'etanargemo'

>>> fruit[-1:-12:-1]

'etanargemop'

>>> fruit[:6:]

'pomegr'

>>> fruit[-6:-12:-1]

'rgemop'

>>> fruit[-1::-1]

'etanargemop'

>>> fruit[0:]

'pomegranate'

>>> fruit[::]

'pomegranate'

>>> fruit[:5:]

'pomeg'

>>> fruit[0:5:1]

'pomeg'

>>> 

Comments

Popular posts from this blog

XAMPP, SQL BASIC COMMANDS

The Minion Game Hackerrank Solution

Arrays - DS | HackerRank Solutions