Python 使用print()函数输出

2021年3月10日15:50:50 发表评论 764 次浏览

产生输出的最简单方法是使用打印()该函数可以传递零个或多个用逗号分隔的表达式。此函数在写入屏幕之前将你传递的表达式转换为字符串。

语法:print(value(s), sep =‘’, end =‘\ n', file = file, flush = flush)参数:value(s):任意值, 并且可以任意设置。在打印出来之前将转换为字符串sep ='separator':(可选)如果有多个对象, 则指定如何分离对象默认值:''end ='end':(可选)指定最后打印的内容.Default:'\ n'文件:(可选)具有write方法的对象。默认值:sys.stdout flush:(可选)布尔值, 指定输出是刷新(True)还是缓冲(False)。默认值:False返回:将输出返回到屏幕。

代码1:使用打印()Python(2.x)中的函数

# Python 2.x program showing
# how to print data on
# a screen
  
# One object is passed
print "lsbin"
  
# Four objects are passed
print "Geeks" , "For" , "Geeks" , "Portal"
  
l = [ 1 , 2 , 3 , 4 , 5 ]
# printing a list
print l

输出如下:

lsbin
Geeks For Geeks Portal
[1, 2, 3, 4, 5]

代码2:

使用

打印()

Python(3.x)中的函数

# Python 3.x program showing
# how to print data on
# a screen
  
# One object is passed
print ( "lsbin" )
  
x = 5
# Two objects are passed
print ( "x =" , x)
  
# code for disabling the softspace feature 
print ( 'G' , 'F' , 'G' , sep = '')
  
# using end argument
print ( "Python" , end = '@' )  
print ( "lsbin" )

输出如下:

lsbin
x = 5
GFG
Python@lsbin

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

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


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: