Python 入门速成练习
for循环学习使用:
系统自带的String.isdigit()的方法,该方法用于判定输入的字符串是否为纯数。
ptr = []
for i in range(5):
num = int(input('please input a number:\n'))
ptr.append(num)
print(ptr)

ptr = []
for i in range(5):
num =input('please input a number:\n')
if num.isdigit(): #
ptr.append(num)
else:
print('输入错误!')
print(ptr)

本文通过两个实例深入讲解Python中for循环的应用,以及如何使用内置方法isdigit()来判断字符串是否全为数字,适用于Python初学者快速掌握基础语法。

2万+

被折叠的 条评论
为什么被折叠?



