python學習之控制流1

  • 2020 年 1 月 16 日
  • 筆記

配置環境:python 3.6 python編輯器:pycharm  程式碼如下:

#!/usr/bin/env python  #-*- coding: utf-8 -*-      # 控制流:  # 1、布爾值:只有兩種值:Ture 和 False  A = True    #要是寫為true,或則使用Ture或則False為變數名,都會報錯。  print(A)    # 2、比較操作符:  # 操作符      含義  # ==          等於            備註:== 是問兩個值是否彼此相同,= 將右邊的值放到左邊的變數中  # !=          不等於  # <           小於  # >           大於  # <=          小於等於  # >=          大於等於  # == 和!= 操作符實際上可以用於所有數據類型的值  #<、 >、<=、>=操作符僅用於整型和浮點型值  print(42 == 42)  print(42 == 22)  print(2 != 3)  print(2 != 2)  print('hello' == 'hello')  print(42 == '42')   # 整數42與字元串『42』不同 所以結果為False  print(42 < 100)  print(42 > 100)  print(42 < 42)    eggCount = 42  print(eggCount <= 42)    # 布爾操作符:二元布爾操作符 、 not操作符、混合布爾和比較操作符  #二元布爾操作符:and 和 or  #and:將表達式求值為True 否則求值為false  print(True and True)  print(True and False)    #and的真值表  # 表達式             求值為  # True and True       True  # True and False      False  # False and False      False  #or:將表達式求值為True 如果都為False  print(False or True)  print(False or False)  print(True or True)    #or的真值表  # 表達式             求值為  # True or True       True  # True or False      True  # False or False      False    #not操作符:只作用一個布爾值或則表達式。not操作符求值為相反的布爾值  print(not True)  print(not not not not True)     #雙重否定為肯定  #not的真值表  # 表達式             求值為  # not True            False  # not False           True    #混合布爾:混合布爾就是把and 、or、not、比較操作符組合在一起使用  print((4 < 5) and (5 < 9))  print((4 < 5) and (5 > 9))  # # (4 < 5) and (5 < 9)順序為  # # True and (5 < 9)  # # True and True  # # True