Python變數命名規則

來源:互聯網
上載者:User

標籤:glob   lam   nbsp   net   大寫   聲明   tin   大小   final   

變數的命名規則
1、要具有描述性
2、變數名只能_,數字,字母組成,不可以是空格或者特殊字元([email protected]#$%^&*~)
3、不能以中文為變數名
4、不能以數字開頭
5、變數名區分大小寫
6、保留字元不能使用來命名
以下關鍵字(保留字元)不能聲明為變數名
[‘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‘]

例:

student_number=30  #Python官方建議命名規則
studnetNumber=30  #駝峰體

常量
在Python裡面沒有常量,所有的量都是可變的,
為了區分常量和變數,常量用全部大寫的變數名代表此變數為常量

 

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.