首页 > 其他分享 >Pycharm中print函数有end= 参数,控制台不打印输出

Pycharm中print函数有end= 参数,控制台不打印输出

时间:2023-06-19 12:33:56浏览次数:38  
标签:square end 函数 打印输出 print Pycharm 控制台

Pycharm中print函数有end= 参数,控制台不打印输出

for i in range(1, 256):  # 寻找对称平方数
    square = str(i*i)  # 转为字符串
    if square == square[::-1]: 
        print(i, end='\t')

循环中 print函数有end= 参数, 无论 end='\t' 还是 end='' end='9' end='a',Pycharm运行后都不会输出。

后面加一句空打印print()即可。这句的作用只是打印一个换行

for i in range(1, 256):  # 寻找对称平方数
    square = str(i*i)  # 转为字符串
    if square == square[::-1]: 
        print(i, end='\t')
print()

 

猜测Pycharm是一行的内容一起输出的,所以没有换行内存一直积压在缓存

print()函数输出的时候必须以换行符‘\n’结尾才会输出到控制台,否则print()函数会继续等待输出。

 

另一种验证是读取文件文本内容,暂停0.05秒读取下一个,此时不是0.05面后显示下一个字符,而是等一行全部读取完毕,遇到换行符才会显示出来

import time
with open('./code/0.txt', encoding=fc) as f:
    while 1:
        char = f.read(1)
        if not char:
            break
        print(char, end='')
        time.sleep(0.05)

  

标签:square,end,函数,打印输出,print,Pycharm,控制台
From: https://www.cnblogs.com/sangern/p/17490852.html

相关文章

  • SprintBoot JavaWeb访问提示 Full authentication is required to access this resour
    SprintBoot部署好网站之后访问没有异常,但是配置域名地址至Nginx上时登录请求报错了,经查询是因为项目是前后端分离,请求的路由会加上工程的主路径,所以需要在Nginx多配置一个地址,如Location/{http://localhost:8080/project}location/project/{http://loc......
  • php利用X-sendfile控制下载
    为了控制静态文件下载,一般方法需要PHP用file_get_contents读取文件,再传给客户端。节省资源的方法是利用nginx的x-sendfile模块,原理是nginx上设置一个特殊资源目录,客户端无法直接读取,需要经过php许可后才能下载。 1、设置nginxlocation/request/uri/{internal;alias/re......
  • Databend 开源周报 第 97 期
    Databend是一款现代云数仓。专为弹性和高效设计,为您的大规模分析需求保驾护航。自由且开源。即刻体验云服务:https://app.databend.cn。What'sOnInDatabend探索Databend本周新进展,遇到更贴近你心意的Databend。列位置Databend现在支持$N这一语法,用来表示列位置,例......
  • Go 语言之 Shutdown 关机和fvbock/endless 重启
    Go语言之Shutdown关机和fvbock/endless重启Shutdown源码//Shutdowngracefullyshutsdowntheserverwithoutinterruptingany//activeconnections.Shutdownworksbyfirstclosingallopen//listeners,thenclosingallidleconnections,andthenwaiting......
  • 552.Student Attendance Record II (Hard)
    Description552.StudentAttendanceRecordII(Hard)Anattendancerecordforastudentcanberepresentedasastringwhereeachcharactersignifieswhetherthestudentwasabsent,late,orpresentonthatday.Therecordonlycontainsthefollowingthre......
  • hObject==handles.pushbutton1;sprintf('handles.pushbutton1 is %d',handles.pushbutt
    %---Executesonbuttonpressinpushbutton1.functionpushbutton1_Callback(hObject,eventdata,handles)%hObjecthandletopushbutton1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandles......
  • export /opt/FriendlyARM/toolschain/4.5.1/bin/:$PATH
    [root@tom/]#arm-linux-gcc-vbash:arm-linux-gcc:commandnotfound...[root@tom/]#export/opt/FriendlyARM/toolschain/4.5.1/bin/:$PATH-bash:export:`/opt/FriendlyARM/toolschain/4.5.1/bin/:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin......
  • Logback SiftingAppender 使用
    1、简介SiftingAppender可根据给定的运行时属性将日志分离或筛选。例如,SiftingAppender可以根据用户会话将日志事件分开,以便不同用户生成的日志进入不同的日志文件,每个用户一个日志文件。SiftingAppender有两个属性:timeoutSiftingAppender会关闭并取消引用超时(连续多长时......
  • Go 中的格式化字符串`fmt.Sprintf()` 和 `fmt.Printf()`
    在Go中,可以使用fmt.Sprintf()和fmt.Printf()函数来格式化字符串,这两个函数类似于C语言中的scanf和printf函数。fmt.Sprintf()fmt.Sprintf()函数返回一个格式化后的字符串,而不是将其打印到标准输出流中。下面是一个例子:packagemainimport"fmt"funcmain(){......
  • Blender-Texture
    建立模型之后点击导出UV布局图,记得选中物体之后,切换到编辑模式 uv自动展开: 然后使用ps对布局图绘制,然后切换到Shading 完成纹理绑定......