Python基礎文法

來源:互聯網
上載者:User

標籤:return   語言   檔案編碼   imp   使用   字母   大小寫   字母數   標識   

編碼

Python源碼檔案以UTF-8編碼 字串是Unicode編碼

 # -*- coding: cp-1252 -*- 指定源碼檔案編碼方式

 

標識符

使用字母數字底線

首字元為大小寫字母或底線

大小寫敏感

 

保留字

>>> import keyword>>> keyword.kwlist[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘nonlocal‘, ‘not‘, ‘or‘, ‘pass‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]

 

注釋

單行注釋:#開頭

多行注釋:‘‘‘ 或 """

# 注釋 ‘‘‘注釋注釋‘‘‘ """注釋注釋"""

 

縮排

縮排來代表代碼塊而不使用{} 和其他語言不同

縮排的空格數可變 但同一個代碼塊必須縮排相同的空格數

 

多行語句

#使用反斜線\實現多行S = 1 +     2 + \        3#在 [], {}, 或 () 中的多行語句,不需要使用反斜線(\)Y  = [‘S‘, ‘Y‘,     ‘Z‘]   

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.