python中的多行字符串及文档字符串

来源:互联网 发布:python数据类型有哪些 编辑:程序博客网 时间:2024/05/30 23:02

看到python中的多行字符串,感觉很新颖,试了下,编译出错。原来是受以前PHP的影响,用了一个双引号和一个单引号。。


GOOGLE了下,没有直接的看到有说的,仔细看了下别人的代码原来是三个单引号。。晕了一阵。。。。顺便又看到了docString...

很特别。。。以下代码来自《简明python教程里的》

Code:
  1. #!/usr/bin/python  
  2. # Filename: func_doc.py  
  3. def printMax(x, y):  
  4.   '''Prints the maximum of two numbers. 
  5.   The two values must be integers.'''  
  6.   x = int(x) # convert to integers, if possible  
  7.   y = int(y)  
  8.   if x > y:  
  9.      print x, 'is maximum'  
  10.   else:  
  11.      print y, 'is maximum'  
  12. printMax(35)  
  13. print printMax.__doc__  

 

Code:
  1. 输出  
  2. $ python func_doc.py  
  3. 5 is maximum  
  4. Prints the maximum of two numbers.  
  5.      The two values must be integers.  

docString具体应用这里就不详细说了,简明教程上说的有,不过不太详细,有google,怕啥..

原创粉丝点击