** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
if is_ok:
print('OK!')
else:
print('No!')
Prepare and put various things in ʻis_ok` and try it.
is_ok
is_ok = 1
if is_ok:
print('OK!')
else:
print('No!')
result
OK!
is_ok
is_ok = 0
if is_ok:
print('OK!')
else:
print('No!')
result
No!
If the variable is assigned a number
If ** 0 **, it will be False
in the if statement,
If it is a number other than ** 0 (positive or negative), it will be True
in the if statement.
You can use this to find out if a variable has a non-zero value assigned to it.
False
0
(int type)
0.0
(float type)
''
(str type)
[]
(list type)
()
(tuple type)
{}
(dict type)
set ()
(set type)
Recommended Posts