zogo
zogo

Reputation: 515

want to know in broad the usage of indices in Python

i am new in python,

my question is that ,why we use indices [1:-1] while want get output of any string such as

 v= ['Name','Position','Join_date']
 print (str(v)[1:-1])

i notice that if i don't use the indices then there is no output is showing.why?

please help me and it will be great if you give me a tutorial link about the usage of indices in Python.

Thank You.

Upvotes: 1

Views: 41

Answers (1)

shyam
shyam

Reputation: 9368

[1:-1] are used to remove the beginning [ and closing ] of the output of str(v)

>>> v= ['Name','Position','Join_date']
>>> print(str(v))
['Name', 'Position', 'Join_date']
>>> print(str(v)[1:-1])
'Name', 'Position', 'Join_date'

Upvotes: 1

Related Questions