简体   繁体   English

从输出中删除新行

[英]Remove new line from output

I have the below function:我有以下功能:

i = 1
h_ = 4
for i in range(h_+1):
    w_i = " " * (h_ - i)
    h_i = "*" * i
    pyramid =  w_i + h_i
    print(pyramid)
i+1

Actual output:实际输出:

$ python test.py

   *
  **
 ***
****

Expected output:预期输出:

$ python test.py
   *
  **
 ***
****

How do I remove the new line at the beginning of the output?如何删除输出开头的新行?

Thank you谢谢

just make a small change in your for loop as below,只需在你的 for 循环中做一个小的改变,如下所示,

i = 1
h_ = 4
for i in range(1, h_+1):
    w_i = " " * (h_ - i)
    h_i = "*" * i
    pyramid =  w_i + h_i
    print(pyramid)

start the for loop with 1.以 1 开始 for 循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM