一豪叔叔 2019-03-12 08:05 采纳率: 100%
浏览 2902
已采纳

python 列表 元素 选取

def text_furface_get():

    text =[memeda','wtf','hello','vaseline','fuckthatbitch','this is a new world','we are the champion']
    x = N.random.randint(0,len(text) - 1)

    return text[x]



报错:an integer is required (got type tuple)

本来是希望通过用这个函数获取一个字符串的,但是获取text[x]后报错说是一个元组
请问这是怎么回事?要怎么修改才能获取text里面的字符串?

  • 写回答

3条回答 默认 最新

  • 梦想橡皮擦 Python领域优质创作者 2019-03-12 08:23
    关注
    import random
    
    def text_furface_get():
    
        text =['memeda','wtf','hello','vaseline','fuckthatbitch','this is a new world','we are the champion']
        x = random.randint(0,len(text) - 1)
    
        return text[x]
    
    if __name__ == '__main__':
        print(text_furface_get())
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?