Anonymous asked in Computers & InternetProgramming & Design · 9 years ago

How do I get python to print a specific position within a range?

The headline question does not justify what I am asking. However, what I am asking is how I get a program to print or display a a character of a certain position within a range. Like if I had

n = range(1,100). Obviously I can just type "print n" and get a sequence of numbers from 1 to 99. But I want to pinpoint a specific number by pointing out its position within the range. If I do not make sense, srry, im new to this.

1 Answer

  • 9 years ago
    Favorite Answer

    The result of the range function is a list. You can specify the index just like any other list. For example:


    x = [5,6,7,8]

    print x[1]

    #output is 6

    print range(5,9)[1]

    #output is 6


Still have questions? Get your answers by asking now.