Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, December 8, 2012

LearnStreet Python Lesson 3 Exercise 6


//sample solution


LearnStreet Python Lesson 3 Exercise 6

Negative Indexing
What if you have a longer string, and wanted the last letter? Python supports negative indexing, which allows you to count positions backwards from the end of the string using negative numbers. For example, the last character is at position -1, the second to last is at position -2, and so on.

We've created an annoyingly long string "This string is so long, it's ridiculous -- no one wants to count all the way to the end!", and stored it in the variable big. Use negative indexing to get the "!" from big.

big[-1]
=> '!'

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts