i have a python string
word = helloworld
the answer for
word[1:9:2] will be given as “elwr”. How this is happening? Thank you!!
i have a python string word = helloworld the answer for word[1:9:2] will be
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re asking for an explanation of Python’s slice notation. See this answer for details. In particular, notice that:
… Is stating that a new slice should be created, beginning at index 1, up to (and not including) index 9, taking one element every two indexes in the string. In other words, create a new string with the following elements:
… And that’s how you obtain
'elwr'as a result.