【Validation】Presence Check on Input

151 阅读1分钟

Method

Problem

Check if an input is empty.

Solution 1

not input

Example 1

a = input('Enter a: ')
while not a:
    a = input('ENTER a: ')

Relative Info

not None == True

not '' == True

not [] == True

⚠ Type of variable cannot be defined when input*, only after. ⚠

Reference

Python 判断是否为空 - tianyaDream

Why is “if not someobj:” better than “if someobj == None:” in Python? - stack overflow