zoukankan      html  css  js  c++  java
  • Python使用print打印时,展示内容不换行


    • 原理

      Python的print()函数中参数end='' 默认为 ,所以会自动换行;

        默认的print()函数:
            print(end='
      ')
      

    • 方案

      Python 2: 在print语句的末尾加上一个逗号, 如print "Hello World",
      Python 3: 把参数end设置成你想要的就行了, 如print("Hello World", end="")


    • 扩展

      补充:其实print()有两个比较重要的可选参数,一个是end 一个是sep

      print()打印中支持常用制表符, 如 ,

        end 在上面已经有介绍了,下面说一下sep,看示例就可以知道具体的意思了:
      
        print('cats', 'dogs', 'mice')   
            输出:  cats dogs mice
      
        print('cats', 'dogs', 'mice', sep = ',')
            输出:  cats,dogs,mice
      
        上述就是用的','替换掉了分隔符 ,当然你也可以用于替换成其他你想要的符号,这个功能有时候会比较有用
      
        譬如2019-10-01是我们祖国70周年
      
        print('2019','10','01', sep='-')
            输出:  2019-10-01
      




    参考

  • 相关阅读:
    angular.isDefined()
    angular.isDate()
    angular.isArray()
    .NET中栈和堆的比较
    SQL Server 2012配置Always On可用性组
    一分钟了解负载均衡的一切
    C# 线程并发锁
    获取Http请求参数
    什么是WCF
    Bitmap算法应用
  • 原文地址:https://www.cnblogs.com/cure/p/14818422.html
Copyright © 2011-2022 走看看