Boolean

  1. Boolean 資料型態值只有 True 及 False 兩種。
    pyuser@deyu:~/zzz$ python
    Python 3.12.9 (main, Aug 14 2025, 00:00:00) [GCC 14.2.1 20250110 (Red Hat 14.2.1-7)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> x=True
    >>> y=False
    >>> print(type(x),type(y))
    <class 'bool'> <class 'bool'>
    
  2. Boolean 值強制轉換成數字,True 為 1,False 為 0。
    >>> print(int(x),int(y))
    1 0
    >>> quit()