在输出末尾获得其他空行

时间:2019-08-22 11:55:20

标签: python python-3.x

在输出的末尾获得另一个空行。

n = 3
space_count = n-1
count = 1

while count <= n:
    print(" " * space_count, "#" * count, end = "")
    space_count = space_count - 1
    count += 1

预期结果:

   #
  ##
 ###

实际结果:

   #  ## ###

1 个答案:

答案 0 :(得分:3)

这是因为您已经专门告诉Python,每行应以空字符串(Type elementType = typeof(List<>); Type typedListType = listType.MakeGenericType(yourTypeInstance); object listInstance = Activator.CreateInstance(typedListType); IList listInstanceAsIList = (IList)listInstance; )结束,而不是换行("")。

将打印行更改为:

\n

这实际上是默认行为。因此,您也可以使用:

print(" " * space_count, "#" * count, end = "\n")