首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python3.3小疑点

2013-08-01 
python3.3小疑问for i in range(0,5):for j in range(0,5):print(*),print如何让内循环里的*输出在一行

python3.3小疑问
for i in range(0,5):
    for j in range(0,5):
            print('*'),
    print
如何让内循环里的*输出在一行 python3.3版的 Python
[解决办法]
看文档。print有可选参数end。

~/tmp/ ipython3 
Python 3.2.4 (default, May  8 2013, 20:55:18) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: print?
Type:       builtin_function_or_method
String Form:<built-in function print>
Namespace:  Python builtin
Docstring:
print(value, ..., sep=' ', end='\n', file=sys.stdout)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep:  string inserted between values, default a space.
end:  string appended after the last value, default a newline.

In [2]: for i in range(5):
   ...:     for j in range(5):
   ...:         print('*', end='')
   ...:     print('')
   ...:     
*****
*****
*****
*****
*****

In [3]: 

热点排行