Python Forum
TypeError: string indices must be integers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: string indices must be integers
#1
given the code snippet:
i = 0

for key, value in quiz.items():
    i += 1
    print(f"Question {str(i)} : {key['question']}")
Line 5 fails with the error code,
Error:
TypeError: string indices must be integers
The variable named 'i' is clearly an integer. Can someone explain why it fails with this error?
Yoriz write Aug-30-2022, 02:04 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
TypeError: string indices must be integers - by JonWayn - Aug-30-2022, 01:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tuple indices must be integers or slices, not str cybertooth 16 11,927 Nov-02-2023, 01:20 PM
Last Post: brewer32
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,283 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,351 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,554 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 2,104 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error "list indices must be integers or slices, not str" dee 2 1,511 Dec-30-2022, 05:38 PM
Last Post: dee
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,959 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,668 Apr-22-2022, 10:56 AM
Last Post: Anldra12
  string indices must be integers when parsing Json ilknurg 3 6,509 Mar-10-2022, 11:02 AM
Last Post: DeaD_EyE
  TypeError: not enough arguments for format string MaartenRo 6 3,001 Jan-09-2022, 06:46 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020