Computer Science, asked by TbiaSamishta, 10 months ago

“TypeError: string indices must be integers'? why?


ghalacoa: are you coding with python?

Answers

Answered by ghalacoa
0

this error happens when you want an index of a list but you entered the index as string.for example the code below is wrong:

a=input()

List=[1,2,3,4]

print(List[a])

>>>TypeError: list indices must be integers or slices, not str>>>

-------------------

this code is correct

a=int(input())

List=[1,2,3,4]

print(List[a])

Answered by aqibkincsem
0

"import github3

from github3 import login, GitHub

import requests

import json

import sys

auth = dict(username=""xxxxxxxxx"",token=""xxxxxxxxx"")

gh = login(**auth)

result = gh.repository(owner=""xxx"", repository=""xxxx"").pull_request(x)

data  = result.as_dict()

print data['title']['number']

auth = dict(username='larsks', token='mytoken')

gh = login(**auth)

result = gh.repository(owner='ansible', repository='ansible').pull_request(12165)

data = result.as_dict()

data['title'] is a string so that the token will be open in the condition and teh rest will be dertmined based on differnet if statement.

"

Similar questions