程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Getting started with Python - variables, constants

編輯:Python

Variable

Python  The variable of , It's underline (_) And the names of English numbers . In the beginning 1 Text must be underlined (_) Or letters .

value1 = 123
_value1 = 123
test_value = 123
TEST_VALUE = 123

 

Constant

Python Constant types are not supported . Habitual capital letters and underscores (_) To name .

PI = 3.14
MAX_BUFFER_SIZE = 1024

 

Document reference (__doc__)

module The beginning of ,class The beginning of , The function starts with triple double quotation marks """..."""  Notes 、 As a document comment  __doc__  You can refer to the notes .

 

mymod.py

 

Python

"""A sample module"""
class MyClass:
"""A sample class"""
def myfunc(self, x, y):
"""A sample function"""
return x + y

mytest.py

 

Python

import mymod
print mymod.__doc__ #=> A sample module
print mymod.MyClass.__doc__ #=> A sample class
print mymod.MyClass.myfunc.__doc__ #=> A sample function

 help() You can also access notes .

Linux

$ python
>>> import mymod
>>> help(mymod)
Help on module mymod:
NAME
mymod - A sample module
FILE
/root/mymod.py
CLASSES
MyClass
class MyClass
| A sample class
|
| Methods defined here:
|
| myfunc(self, x, y)
| A sample function

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved