python 學習 D2

來源:互聯網
上載者:User

標籤:loop   老男孩   格式   比較   姓名   情況   false   not   each   

格式化輸出。%s %d

# name = input(‘請輸入名字:‘)# age = input(‘請輸入年齡:‘)# sex = input(‘請輸入性別:‘)## msg = ‘我的名字是‘ + name + ‘我的年齡是‘ + age + ‘我的性別是‘ + sex# print(msg)msg = ‘‘‘------------ info of Alex Li -----------Name  : Alex LiAge   : 22job   : TeacherHobbie: girl------------- end -----------------‘‘‘

 

# 格式化輸出  %預留位置  s d# name = input(‘請輸入姓名:‘)# age = int(input(‘請輸入年齡:‘))# job = input(‘請輸入工作:‘)# hobby=input(‘請輸入愛好:‘)## msg = ‘‘‘# ------------ info of %s -----------# Name  : %s# Age   : %d# job   : %s# Hobbie: %s# ------------- end -----------------# ‘‘‘ % (name, name, age, job, hobby)# print(msg)

 

#第二種使用方法# dic = {#     ‘name‘:‘老男孩‘,#     ‘age‘:58,#     ‘job‘:‘boss‘,#     ‘hobby‘:‘money‘,# }# msg = ‘‘‘# ------------ info of %(name)s -----------# Name  : %(name)s# Age   : %(age)d# job   : %(job)s# Hobbie: %(hobby)s# ------------- end -----------------# ‘‘‘ % dic# print(msg)

 

# 格式化輸出,在格式化輸出中,單純的表示% 需要用%% 去表示。
# msg = ‘我叫%s,今年%s,學習進度2%%‘ % (‘爽妹兒‘,‘18‘)
# print(msg)

03,while else

#while  else 當while迴圈被break打斷,則不走else程式。
# count = 0# while count <= 5:#     count += 1#     print("Loop",count)#     if count == 4: break## else:#     print("迴圈正常執行完啦")# print("-----out of while loop ------")
04,運算子。
# print(2 > 1 and 3 < 4 or 8 < 10 and 4 > 5)
# 第一種情況 邏輯運算子前後都是比較運算
# 優先順序概念:() > not > and > or,同一優先順序從左至右以此計算。
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)  # T# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)  # F# print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
# 第二種情況 邏輯運算子前後都是數字
‘‘‘x or y if x True,return x,else y‘‘‘# print(3 or 5)# print(2 or 5)# print(0 or 5)# print(-4 or 5)#print(3 and 5)# print(1 or 3 or 4 or 0)# print(1 or 3 or 0)
# print(1 > 2 and 3 or 4)
 

 


‘‘‘數字與bool值轉化int ---> bool  非零 True ,零 Falsebool---> int   True  1, False 0,‘‘‘# print(bool(100))# print(bool(0))

05,編碼初識。

 

    諜戰片:嘀嘀嘀 滴滴  高低電平,0101010

    電腦檔案的儲存,與檔案的傳輸   010101010

    初級密碼本 :ascii   字母,數字,特殊字元。

                0000 0001 8位== 1個位元組  一個位元組表示一個字元。

                字元:組成內容的最小單元。 abc  a  b   c

                                         中國  中  國

 

                a  01100001

                b  01100010

                c  01100011

 

    萬國碼:unicode

        建立初期 16位 兩個位元組表示一個字元。

            a :01100001 01100001

            中:01100011 01100001

 

        升級:32位 四個位元組表示一個字元。

            a :01100001 01100001 01100001 01100001

            中:01100011 01100001 01100011 01100001

            資源浪費。

    對Unicode升級 :utf-8。

        utf-8:最少用8位元去表示一個字元。

            a:01100001(字母用1個位元組表示。)

            歐洲文字:01100001 01100001(歐洲用2個位元組表示。)

            亞洲文字——中:01100001 01100001 01100001 (歐洲用3個位元組表示。)

        utf-16:最少用16位元去表示一個字元

 

    gbk:國家標準。

        a : 01100001

        中: 01100001 01100001

 

    8位  1個byte

    1024bytes  1kb

    1024kb   1MB

    1024MB   1GB

    1024GB   1TB

python 學習 D2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.