Python基礎學習之標識符

來源:互聯網
上載者:User

標籤:劃線   第一個字元   特殊變數   1.5   color   nbsp   code   避免   oba   

1、合法的Python標識符

  Python標識符字串規則和其他大部分用C編寫的進階語言相似:

  • 第一個字元必須是字母或底線(_)
  • 剩下的字元可以是字母和數字或下滑線
  • 大小寫敏感

  標識符不能以數字開頭;除了底線,其他的符號都不允許使用。

2、關鍵字
1 >>> import keyword2 >>> print(keyword.kwlist)3 [‘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‘]
 3、專用底線標識符

   Python用底線作為變數首碼和尾碼制定特殊變數。

  • 一般來講_xxx被看做是私人的,在模組或類外不可以使用。
  • __xxx__ 系統定義名字
  • __ 類中私人變數名。

   避免用底線做為變數名的開始!

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.