问题出在标题中.
我想在python中做到这一点 .我想在c中的这个例子中做些什么:
#include <stdio.h>
int main() {
int i;
for (i=0; i<10; i++) printf(".");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
..........
Run Code Online (Sandbox Code Playgroud)
在Python中:
>>> for i in xrange(0,10): print '.'
.
.
.
.
.
.
.
.
.
.
>>> for i in xrange(0,10): print '.',
. . . . . . . . . .
Run Code Online (Sandbox Code Playgroud)
在Python中print会添加一个\n或一个空格,我该如何避免呢?现在,这只是一个例子.不要告诉我,我可以先构建一个字符串然后打印它.我想知道如何"附加"字符串stdout.
在Python中,我想将列表中的所有字符串转换为整数.
所以,如果我有:
results = ['1', '2', '3']
Run Code Online (Sandbox Code Playgroud)
我该怎么做:
results = [1, 2, 3]
Run Code Online (Sandbox Code Playgroud) 我想做几个语句,给出标准输出,而不会在语句之间看到换行符.
具体来说,假设我有:
for item in range(1,100):
print item
Run Code Online (Sandbox Code Playgroud)
结果是:
1
2
3
4
.
.
.
Run Code Online (Sandbox Code Playgroud)
如何让它看起来像:
1 2 3 4 5 ...
Run Code Online (Sandbox Code Playgroud)
更妙的是,是否可以打印单号在最后一个号码,所以只有一个号码在屏幕上在同一时间?
我想运行一个脚本,它基本上显示如下内容:
Installing XXX... [DONE]
Run Code Online (Sandbox Code Playgroud)
现在,此刻,我在功能成功后使用print打印整行.但是,我现在希望它首先打印"安装xxx ...",并在功能运行之后添加"DONE"标签; 但是在同一条线上.
有任何想法吗?
我想将循环输出打印到同一行的屏幕上.
我如何以最简单的方式处理Python 3.x.
我知道这个问题已经被要求用于Python 2.7,在行的末尾使用逗号即打印I,但我找不到Python 3.x的解决方案.
i = 0
while i <10:
i += 1
## print (i) # python 2.7 would be print i,
print (i) # python 2.7 would be 'print i,'
Run Code Online (Sandbox Code Playgroud)
屏幕输出.
1
2
3
4
5
6
7
8
9
10
Run Code Online (Sandbox Code Playgroud)
我想要打印的是:
12345678910
Run Code Online (Sandbox Code Playgroud)
新读者访问此链接以及http://docs.python.org/release/3.0.1/whatsnew/3.0.html
我是python的新手,我试图在一行中扫描多个以空格分隔的数字(让我们假设'1 2 3'为例)并将其添加到int列表中.我这样做是通过使用:
#gets the string
string = input('Input numbers: ')
#converts the string into an array of int, excluding the whitespaces
array = [int(s) for s in string.split()]
Run Code Online (Sandbox Code Playgroud)
显然它可以工作,因为当我输入'1 2 3'并做一个print(array)输出是:
[1,2,3]
但是我想在没有括号的单行中打印它,并且在数字之间有一个空格,如下所示:
1 2 3
我试过做:
for i in array:
print(array[i], end=" ")
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
2 3追溯(最近一次通话):
print(array [i],end ="")
IndexError:列表索引超出范围
如何在一行中打印整数列表(假设我的前两行代码是正确的),没有括号和逗号?
python ×6
printing ×3
python-3.x ×2
int ×1
line-breaks ×1
list ×1
newline ×1
python-2.x ×1
stdout ×1