个性化阅读
专注于IT技术分析

Python print()中的end参数用法详细介绍

点击下载

默认情况下, python的print()函数以换行符结尾。具有C/C++背景的程序员可能想知道如何在不使用换行符的情况下进行打印。

Python的print()函数带有一个名为”end”的参数。默认情况下, 此参数的值为” \ n”, 即换行符。你可以使用此参数以任何字符/字符串结束打印语句。

# This Python program must be run with
# Python 3 as it won't work with 2.7.
  
# ends the output with a <space> 
print ( "Welcome to" , end = ' ' ) 
print ( "srcmini" , end = ' ' )

输出:

Welcome to srcmini

另一个程序演示end参数的工作。

# This Python program must be run with
# Python 3 as it won't work with 2.7.
  
# ends the output with '@'
print ( "Python" , end = '@' ) 
print ( "srcmini" )

输出:

Python@srcmini

本文作者:安吉·邦达尔(Ankit Bindal)。如果你喜欢srcmini并希望做出贡献, 那么你也可以写一篇文章并将你的文章邮寄到contribution@srcmini.org。查看你的文章出现在srcmini主页上, 并帮助其他Geeks。

如果发现任何不正确的地方, 或者想分享有关上述主题的更多信息, 请发表评论。

注意怪胎!巩固你的基础Python编程基础课程和学习基础知识。

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。

赞(1)
未经允许不得转载:srcmini » Python print()中的end参数用法详细介绍

评论 抢沙发

评论前必须登录!