首页 > 编程知识 正文

python print用法换行,Python print 换行

时间:2023-05-04 14:05:53 阅读:248948 作者:2567

之前一直没有注意到这个细节,请看

def pt1():print('*')print('*')pt1()

result:

**

可见print函数默认在结尾有个换行,如果不想换行,可在实参中加end=''或者任意拼接字符串

def pt1():print('*',end='')print('*')pt2()

result

** 案例1:打印小星星 def printstar(): row = 1 while row <= 5: col = 1 while col <= row: print('*',end='') col += 1 print('') row += 1 printstar() *************** 案例2:九九乘法表

def ptmul(): row = 1 while row <= 9: col = 1 while col <= row: print("{}*{}={}".format(col, row, col*row),end='t') col += 1 print('') # 执行换行 row += 1 ptmul() 1*1=11*2=22*2=41*3=32*3=63*3=91*4=42*4=83*4=124*4=161*5=52*5=103*5=154*5=205*5=251*6=62*6=123*6=184*6=245*6=306*6=361*7=72*7=143*7=214*7=285*7=356*7=427*7=491*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=641*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81
javascript中有哪些类型历史中提交的图片或压缩文件

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。