How do I get python to print a specific position within a range?
January 24, 2012 – 8:36 pmThe 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.
Related posts:
- Can I print output based on a range in Python?
- How to print a position number from a file in Java?
- Python question, if i need to design a python program that has a range specified by the user, how do i count?
- Python: Reversing a string by changing the range of the for loop?
- is it possible to print the items in a python list sans the lowest?
- setting desktop icon position using python?
- Why is print a keyword in Python?
- What are other ways can i use instead of a print statement in python?
- Python, I am trying to print out a list of factorials starting at 0 and going to an inputed number.?
- In Python. Prompt the user for an input integer and then print the next 10 numbers?
One Response to “How do I get python to print a specific position within a range?”
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
—-
By ChaosGrimm on Jan 24, 2012