day02_步入百萬年薪的次日

day02

while--關鍵字(死循環)

  • 格式:while 條件:python

    ​ 循環體linux

    print(1)
    while True:
        print("癢")
        print("雞你太美")
        print("卡路里")
        print("好運來")
        print("小三")
        print("小白臉")
        print("趁早")
        print("過火")
    print(2)
    
    falg = True
    while falg:
      print(1)
    print(2)
    
    
    # 正序的示範
    count = 1
    while count <= 5:
        print(count)
        count = count + 1
    
    # 倒序的示範
    count = 5
    while count:
        print(count)
        count = count - 1
    
    # 正序打印  25 - 57
    count = 25
    while count < 58:
        print(count)
        count = count + 1
    
    
    # 倒序打印  57 - 25
    count = 57
    while count > 24:
        print(count)
        count = count - 1
  • 數字中非零都是True 零是Falsewindows

    # print(bool(0))
    # 數字中非零的都是True
  • break:終止循環,break下面的代碼不會執行學習

    while True:
        print(123)
        print(234)
        break   # 終止當前循環,break下方的代碼不會進行執行
        print(345)
    print(1111)
  • continue:結束本次循環,直接跳入下一次循環(假裝成循環體中的最後一行),下面的代碼不會執行編碼

    while True:
        print(123)
        print(234)
        print(345)
    
    while True:
        print(123)
        print(234)
        continue
        #continue 假裝成循環體中的最後一行代碼(跳出當前循環繼續下次循環)
        #continue 下面的代碼不會執行
        print(345)
    print(1111)
  • while else :是一個整體(循環),當條件成立的時候不執行,當條件不成立的時候執行code

    while True:
        print(111)
        break
    else:
        print(222)
    
    while True:
        print(111)
        break
    print(222)
    
    # while   else
    # 0.退出
    # 1.開始登陸
    # 若是用戶選擇序號0就提示用戶退出成功
    # 若是用戶選擇序號1就讓用戶輸入用戶名和密碼而後進行判斷,正確就終止循環,錯誤就從新輸入
    srr = """
    0.退出
    1.開始登陸
    """
    print(srr)
    num = int(input("請輸入你要的數字:"))
    while num == 1:
        name_input = input("請輸入你的用戶名:")
        password_input = input("請輸入你的密碼:")
        name = "alex"
        password = "123"
        if name_input == name and password_input:
            print("登陸成功")
            break
        else:
            print("用戶名或者密碼錯誤,請從新輸入!")
    else:
        print("退出成功")
  • 總結:utf-8

    • 打斷循環的方式:
      1. 本身修改條件
      2. break
  1. break -- 打破當前循環 (終止當前循環)ci

    1. continue -- 跳出當前循環繼續下次循環(將continue假裝成循環體中的最後一個行代碼)
    2. break和continue相同之處:他們如下的代碼都不執行

字符串格式化

a = "------------- info -------------"
b = "name:"
c = "age:"
d = "job:"
e = "-------------- end -------------"
name = input("name")
age = input("age")
job = input("job")
print(a + "\n" + b + name + "\n" + c + age + "\n"+ d + job + "\n" +e)
  • %就是佔位unicode

  • %%(轉義) 轉義成普通的%字符串

  • %s 是佔的字符串類型的位置

  • %d 是佔的數字類型的位置

  • 按照位置順序傳遞,佔位和補位必需要一一對應

    s = """ ------------- info -------------
    name:%s
    age:%s
    job:%s
    -------------- end -------------
    """
    name = input("name")
    age = int(input("age"))
    job = input("job")
    print(s%(name,age,job))
    
    # num = input("學習進度:")
    # s = "大哥黑的學習進度爲:%s%%"
    # print(s%(num))
    
    # num = input("學習進度:")
    # num1 = input("aaaa:")
    # s = "大哥黑的學習進度爲:%s%"
    # print(s%(num,num1))
    
    # num = input("學習進度:")
    # num1 = input("aaaa:")
    # s = "大哥黑的學習進度爲:%s%s"
    # print(s % (num, num1))
  • 擴展:f"{變量名}{字符串}"3.6版本及以上才能使用

    # s = f"今天下雨了{input('>>>')}"
    # print(s)
    
    # s = f"大黑哥的學習進度爲{input('<<<')}"
    # # print(s)
    
    # s = f"{1}{2}{3}"
    # print(s)

運算符

算術運算符
  • / 除({5/2結果}python2中結果是整數,python3中結果是小數)
  • // 整除(地板除)
  • ** 冪(次方)
  • % 模(取餘)
比較運算符
  • --- >
  • --- <
  • --- ==
  • --- !=
  • --- >=
  • --- <=
賦值運算符
  • = 賦值
  • += 自加
  • -= 自減
  • *= 自乘
  • /= 自除
  • //=
  • **=
  • %=
邏輯運算符
  • and (與):全真則真、

    • 都爲真的時候取and後面的值
    • 都爲假的時候取and前面的值
    • 一真一假取假的值
    # print(3 and 4)
    # print(0 and 4)
    # print(0 and False)
    
    # print(3 and 5 and 9 and 0 and False)
    # print(5 and False and 9 and 0)
    # print(1 and 2 and 5 and 9 and 6)
  • or(或):一真則真

    • 都爲真的時候取or前面的值
    • 都爲假的時候取or後面的值
    • 一真一假取真的值
    # print(1 or 0)
    # print(1 or 2)
    # print(0 or False)
    # print(1 or 9 or 4 or 0 or 9)
  • not(非):對立的

# print(not False)
  • 級別:()> not > and > or

  • 順序:從左向右執行

    # print(9 and 1 or not False and 8 or 0 and 7 and False)
成員運算符
  • in:存在
  • not in:不存在
# s = "alexdsb"
# if "sb" not in s:
#     print(True)
# else:
#     print(False)

編碼初始

編碼集(密碼本)
# 今 0101
# 天 0110
# 晚 0010
# 上 0001
# 去 1001
# 便 1000
# 利 0100
# 店 1111
#
#
# 00000101  00000110  0010000110011001
  • ascii(美國):不支持中文
  • gbk(國家標準密碼本):英文8位(1字節),中文16位(2字節)
  • unicode(萬國碼):英文16位(2字節),中文32位(4字節)
  • utf-8(可變長的編碼,最流行的):英文8位(1字節),歐洲文16位(2字節),亞洲24位(3字節)
  • linux系統 -- utf-8
  • mac系統 -- utf-8
  • windows系統 -- gbk
  • 單位轉換:
    • 一字節(1Bytes) = 8位(8bit)
    • 1024Bytes = 1KB
    • 1024KB = 1MB
    • 1024MB = 1GB
    • 1024GB = 1TB 經常使用的
    • 1024TB = 1PB
    • 1024PB = 1EB
相關文章
相關標籤/搜索