[Introduction to Udemy Python3 + Application] 37. Techniques for determining that there is no value

** * 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. ** **

■ Is there a value? Isn't it included?

◆ What to use
if is_ok:
    print('OK!')
else:
    print('No!')

Prepare and put various things in ʻis_ok` and try it.

■ Numbers

◆ In case of 1

is_ok


is_ok = 1

if is_ok:
    print('OK!')
else:
    print('No!')

result


OK!
◆ In case of 0

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.

■ What is judged as False

0 (int type) 0.0 (float type) '' (str type) [] (list type) () (tuple type) {} (dict type) set () (set type)

Recommended Posts

[Introduction to Udemy Python3 + Application] 37. Techniques for determining that there is no value
[Introduction to Udemy Python 3 + Application] 54. What is Docstrings?
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
[Introduction to Udemy Python 3 + Application] 57. Decorator
[Introduction to Udemy Python 3 + Application] 56. Closure
[Introduction to Udemy Python3 + Application] 59. Generator
[Introduction to Udemy Python 3 + Application] Summary
[Introduction to Udemy Python3 + Application] 63. Generator comprehension
[Introduction to Udemy Python3 + Application] 28. Collective type
[Introduction to Udemy Python3 + Application] 25. Dictionary-type method
[Introduction to Udemy Python3 + Application] 33. if statement
[Introduction to Udemy Python3 + Application] 13. Character method
[Introduction to Udemy Python3 + Application] 55. In-function functions
[Introduction to Udemy Python 3 + Application] 10. Numerical values
[Introduction to Udemy Python3 + Application] 49. Function citation and return value declaration
[Introduction to Udemy Python3 + Application] 21. Tuple type
[Introduction to Udemy Python3 + Application] 45. enumerate function
[Introduction to Udemy Python3 + Application] 41. Input function
[Introduction to Udemy Python3 + Application] 17. List operation
[Introduction to Udemy Python3 + Application] 65. Exception handling
[Introduction to Udemy Python3 + Application] 11. Character strings
[Introduction to Udemy Python3 + Application] 46. Zip function
[Introduction to Udemy Python3 + Application] 8. Variable declaration
[Introduction to Udemy Python3 + Application] 29. Set method
[Introduction to Udemy Python3 + Application] 16. List type
[Introduction to Udemy Python3 + Application] 61. Dictionary comprehension
[Introduction to Udemy Python 3 + Application] 22. Tuple unpacking
[Introduction to Udemy Python3 + Application] 47. Process the dictionary with a for statement
Note that Python dict returns default value if there is no key
[Introduction to Udemy Python 3 + Application] 26. Copy of dictionary
[Introduction to Udemy Python3 + Application] 23. How to use tuples
[Introduction to Udemy Python3 + Application] 60. List comprehension notation
[Introduction to Udemy Python 3 + Application] 19. Copy of list
[Introduction to Udemy Python3 + Application] 40.while else statement
[Introduction to Udemy Python3 + Application] 62. Set comprehension notation
[Introduction to Udemy Python3 + Application] 64. Namespace and Scope
[Introduction to Udemy Python3 + Application] 67. Command line arguments
[Introduction to Udemy Python3 + Application] 9. First, print with print
[Introduction to Udemy Python3 + Application] 14. Character substitution 15.f-strings
[Introduction to Udemy Python3 + Application] 35. Comparison operators and logical operators
[Introduction to Udemy Python 3 + Application] 66. Creating your own exceptions
[Introduction to Udemy Python3 + Application] 53. Dictionary of keyword arguments
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
[Introduction to Udemy Python3 + Application] 30. How to use the set
[Introduction to Udemy Python3 + Application] 68. Import statement and AS
[Introduction to Udemy Python3 + Application] 52. Tupleization of positional arguments
Introduction to Python For, While
python> How to write multiple lines> How to write in mnist_with_summaries.py> It seems that there is no need for line concatenation symbols
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
[Introduction to Udemy Python3 + Application] 32.1 When one line becomes long
[Introduction to Udemy Python3 + Application] 50. Positional arguments, keyword arguments, and default arguments
[Introduction to Udemy Python3 + Application] 51. Be careful with default arguments
There is no switch in python
An introduction to Python for non-engineers
[Introduction to Udemy Python3 + Application] 69. Import of absolute path and relative path
[Introduction to Udemy Python3 + Application] 12. Indexing and slicing of character strings
Updated "Introduction to Python Web Application Homebrew for Slow 3rd Year Web Engineers"
Updated "Introduction to Python Web Application Homebrew for Slow 3rd Year Web Engineers"
Updated "Introduction to Python Web Application Homebrew for Slow 3rd Year Web Engineers"
Updated "Introduction to Python Web Application Homebrew for Slow 3rd Year Web Engineers"