IndexError: tuple index out of range

MRAB python at mrabarnett.plus.com
Sat May 30 16:33:00 EDT 2009


Invert wrote:
> My simple python script gives me an error when I try to execute it.  
> Here is the error message:
> 
>     daniel at ibex:~/Desktop/python$ python3 str_format2Daniel.py
>     Traceback (most recent call last):
>       File "str_format2Daniel.py", line 8, in <module>
>         print ("{0} is {1} years old {3} and ".format(name, age, append))
>     IndexError: tuple index out of range
>     daniel at ibex:~/Desktop/python$
> 
> 
> Here is my script:
> 
>     #!/usr/bin/python
>     # Filename: str_format2.py
> 
>     age = 23
>     name = 'Daniel'
>     append = '6 months'
> 
>     print ("{0} is {1} years old {3} and ".format(name, age, append))

That should be:

     print ("{0} is {1} years old {2} and ".format(name, age, append))

>     print ('{0} will be an elite python programmer in {2}.'.format(name,
>     append))
> 
> 
> What am I doing wrong?
> 





More information about the Python-list mailing list