How to convert a string list into an integer in python

This question already has an answer here:

  • Get a list of numbers as input from the user 16 answers

  • 使用split()在逗号分割,使用int()将其转换为整数:

    user_lst = map(int, user.split(","))
    

    There's no ' to remove in the list. When you print a list, since it has no direct string representation, Python shows you its repr —a string that shows its structure. You have a list with one item, the string 12,33,223 ; that's what [user] does.

    You probably want to split the string by commas, like so:

    user_list = user_input.split(',')
    

    If you want those to be int s, you can use a list comprehension:

    user_list = [int(number) for number in user_input.split(',')]
    

    [int(s) for s in user.split(",")]
    

    我不知道为什么你定义了单独的userLst变量,它是一个元素列表。

    链接地址: http://www.djcxy.com/p/31802.html

    上一篇: 什么是Python文件的常见标题格式?

    下一篇: 如何将一个字符串列表转换为Python中的整数