python初識

來源:互聯網
上載者:User

標籤:exec   ffffff   使用   必須   字元   utf8   back   lex   style   

一 。python的基礎

  1.編碼

     # -*- coding:utf8 -*-

    意思使用utf8d進行編碼 

    ascill     00000000
       &          00000001
    
       unicode    0000000000000000+
    
        &          0000000000000001
        中         001000000000000111110010
    
        utf-8      能用多少表示就是用多少表示
        在utf-8中 能少就少 特別是在ascill中有的字元編碼
        &          0000 0001
        中         0010 0000 0000 0001 1111 0010

    在python2中 需要用到以上語句

    在python3中 不需要

  2.python的基本輸入輸出語句

 

    n = input(‘請輸入使用者名稱:‘)#  預設input擷取的是字元類型  
    print(n) #

   3.變數名

    字母
     數字
     底線
 
     特例:不能用數字開頭
     Python關鍵字,也不能使用
     ‘and‘, ‘as‘, ‘assert‘,
     ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘,
     ‘else‘, ‘except‘, ‘exec‘, ‘finally‘, ‘for‘, ‘from‘,
     ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘not‘,
     ‘or‘, ‘pass‘, ‘print‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘,
     ‘with‘, ‘yield

二.條件陳述式和基礎資料型別 (Elementary Data Type)

    1.if else語句

      

    n1 = input(‘請輸入:‘)    if n1 == ‘alex‘:        n2 = input(‘>>>‘)        if n2 == ‘確認‘:            print(‘alex sb‘)        else :            print(‘alex db‘)    else:        print(‘error‘)

 

      注意:
            n1 = "alex"   賦值
            n1 == ‘alex‘  比較,

 

      if或者else後面跟著的代碼快最好是4個空格  

      而且必須空格數兩都要一樣

    2.if elif語句

      if 條件1:
            pass
         elif 條件2:
            pass
         elif 條件3:
            pass
         else:
            pass
      
         print(‘end‘)

      

 

python初識

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.