How do I parse a string to a float or int?

后端 未结 29 2874
醉话见心
醉话见心 2020-11-21 04:43

In Python, how can I parse a numeric string like \"545.2222\" to its corresponding float value, 545.2222? Or parse the string \"31\" t

29条回答
  •  [愿得一人]
    2020-11-21 04:55

    By using int and float methods we can convert a string to integer and floats.

    s="45.8"
    print(float(s))
    
    y='67'
    print(int(y))
    

提交回复
热议问题