当前位置:网站首页>How to judge whether the input content is "number"

How to judge whether the input content is "number"

2022-07-07 22:26:00 Happy learning Python

When you want users to enter a number , Will use input function , however input The function does not restrict what the user enters , Users can also enter string or other format content .

Run the following code :

When the user enters the correct number , Output is as follows :

When user input error , Output is as follows

If you want users to input numbers as required, you need to judge the user's input content and then output .

Because the string content cannot be converted to floating point (float), You can convert user input to floating point (float) As the result of the True still False To judge .

Run the following code

If the input is not a number , Output is as follows :

 

 

原网站

版权声明
本文为[Happy learning Python]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130606000435.html