Python String to Int Or None

后端 未结 5 1785
陌清茗
陌清茗 2021-02-05 01:32

Learning Python and a little bit stuck.

I\'m trying to set a variable to equal int(stringToInt) or if the string is empty set to None.

5条回答
  •  不知归路
    2021-02-05 02:14

    this will parse stringToInt to int if it's valid and return original value if it's '' or None

    variable = stringToInt and int(stringToInt)
    

提交回复
热议问题