Discussion Room : IDC101

Queries / doubts

Queries / doubts

by Dr. Amit Kulshrestha -
Number of replies: 1

In this thread you may directly post your queries/doubts/observations related to Python programming. I encourage everyone to participate.

My observation, that I made today only. See this.

s = "Python is great."
print s[::-1][::-1]

Has sometime tried it? Isn't it intriguing?


In reply to Dr. Amit Kulshrestha

Re: Queries / doubts

by Rutvik Kayastha -

As per my simple observations,

s = "Python is great."

  1. print s[2] = t ,print s[2][1] will be absured because "print s[2]" have only 1 char in output. so print s[2][0] will only work.
  2. print s[::-1]=.taerg si nohtyP ,print s[::-1][::-1] will do again do that operation on output so we will get original string inverted back.
  3. so, second bracket applies specified operation in it, on output of first bracket.

Attachment My work 1.JPG