| ���� Python �̳� | ��7�� ���� | |
|---|---|---|
| ��һҳ | DocStrings | ��һҳ |
Python��һ������������ԣ���Ϊ �ĵ��ַ��� ����ͨ�������Ϊ docstrings ��DocStrings��һ����Ҫ�Ĺ��ߣ�������������ij����ĵ����Ӽ�������Ӧ�þ���ʹ�����������������ڳ������е�ʱ�Ӻ����ָ��ĵ��ַ�����
#!/usr/bin/python
# Filename: func_doc.py
def printMax(x, y):
'''Prints the maximum of two numbers.
The two values must be integers.'''
x = int(x) # convert to integers, if possible
y = int(y)
if x > y:
print x, 'is maximum'
else:
print y, 'is maximum'
printMax(3, 5)
print printMax.__doc__
��Դ�ļ���code/func_doc.py��
$ python func_doc.py
5 is maximum
Prints the maximum of two numbers.
The two values must be integers.
�ں����ĵ�һ�����е��ַ�������������� �ĵ��ַ��� ��ע�⣬DocStringsҲ������ģ�����������ǻ��ں�����Ӧ���½�ѧϰ���ǡ�
�ĵ��ַ����Ĺ�����һ�������ַ��������������Դ�д��ĸ��ʼ����Ž�β���ڶ����ǿ��У��ӵ����п�ʼ����ϸ�������� ǿ�ҽ��� ������ĺ�����ʹ���ĵ��ַ���ʱ��ѭ���������
�����ʹ��__doc__��ע��˫�»��ߣ�����printMax�������ĵ��ַ������ԣ����ں��������ƣ������סPython�� ÿһ������ ����Ϊ������������������ǻ��ں������һ��ѧϰ������ڶ����֪ʶ��
������Ѿ���Python��ʹ�ù�help()����ô���Ѿ�������DocStings��ʹ���ˣ���������ֻ��ץȡ������__doc__���ԣ�Ȼ�������չʾ���㡣����Զ����������������һ�¡���ֻ������ij����а���help(printMax)����ס��q�˳�help��
�Զ�������Ҳ������ͬ���ķ�ʽ����ij�������ȡ�ĵ�����ˣ��� ǿ�ҽ��� �������д���κ���ʽ������д�ĵ��ַ����������Python���а渽����pydoc�����help()���Ƶ�ʹ��DocStrings��
| ��һҳ | ��һ�� | ��һҳ |
|---|---|---|
| return��� | ��ҳ | ���� |