当我仅使用以下三个语句之一进行上传时,为什么会有所不同:
print("*", end=" ")
print("* ")
print("*\n")
仅当我在中使用“ end”时,我才能获得https://www.geeksforgeeks.org/programs-printing-pyramid-patterns-python/中所示的金字塔print("*", end=" ")。代码是:
# Function to demonstrate printing pattern
def pypart(n):
# outer loop to handle number of rows
# n in this case
for i in range(0, n):
# inner loop to handle number of columns
# values changing acc. to outer loop
for j in range(0, i + 1):
# printing stars
print("*", end=" ")
# ending line after each row
print("\r")
# Driver Code
pypart(3)
我们为什么需要这行:print("\r")?我没有从那条线上方的评论中得到它。
相关分类