首页 >后端开发 >Python教程 >python 中的 PRINT 函数

python 中的 PRINT 函数

王林
王林原创
2024-07-17 11:34:571217浏览

PRINT function in python

2024年7月13日

打印()函数

print()函数是一个允许我们输出到屏幕的函数

print() 函数有三种不同的用途;

  1. 单引号 (' ')
  2. 双引号 (" ")
  3. 三引号 (“”” “””)------------用于多行

我们可以使用任何人输入的引号,不能在同一行中使用不同的引号

print()---------------------------#create empty line
print("jothilingam")--------------#string should print with""
print(5)------------------------#number can print without ""
print("jo""jo")--------------print without space
print("jo"+"jo")--------------print without space
answer    jojo
print("jo","jo")--------------print with space
answer     jo jo

使用 f 字符串打印

name = "jothi"
print(f"Hello {name}")
# Output : Hello jothi

换行转义字符 n

print("jo\nthi")
jo
thi

print() 函数的参数:

分隔参数

print("jo","jo",sep="_")...................sep="" is default
answer    jo_jo
print("jo", "lingam", sep='thi')
answer     jothilingam

结束参数

print("jothi",end="lingam")
answer  jothilingam
print("jothi",end="")----------------without space
print("lingam")
answer  jothilingam
print("jothi",end=" ")----------------with space
print("lingam")
answer  jothi lingam

* 参数

print(*"jothilingam")
answer    j o t h i l i n g a m

file和flush参数,因为这些参数是允许我们处理文件的参数

以上是python 中的 PRINT 函数的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn