python變量的作用與定義規則

變量的作用: Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program. 變量用於存儲計算機程序中引用和操作的信息。它們還提供了用描述性名稱標記數據的方法,因此讀者和我們自己可以更清楚地理解我們的程序。將變量看作容器來保存信息是很有幫助的。他們唯一的目的是在內存中標記和存儲數據。這些數據可以在整個程序中使用。 變量定義規則: 變量名只能是 字母、數字或下劃線的任意組合 變量名的第一個字符不能是數字 以下關鍵字不能聲明爲變量名['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'] 模塊名,包名 :小寫字母, 單詞之間用_分割。 類名:首字母大寫。 全局變量: 大寫字母, 單詞之間用_分割。 普通變量: 小寫字母, 單詞之間用_分割。 函數: 小寫字母, 單詞之間用_分割。 實例變量: 以_開頭,其他和普通變量一樣 。 私有實例變量(外部訪問會報錯): 以__開頭(2個下劃線),其他和普通變量一樣 。 專有變量: __開頭,__結尾,一般爲python的自有變量(不要以這種變量命名)。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章