网站首页 > 技术文章 正文
入门的时候Python所有 教程都是从第一个hello world开始
print(" hello world ")
print()
print是系统内置的一个函数
print(print) #<built-in function print> print就是一个函数
回顾一个函数定义 f(x,y,z)
def myfunc():
pass
def func2(p2, p2):
pass
def :定义函数关键字
myfunc:函数名
fun2(p2,p2): 函数func2有两个参数p1,p2
函数print的定义是怎么样的呢?
def print(self, *args, sep=' ', end='\n', file=None): # known special case of print
"""
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
"""
pass
"""
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
"""
- print函数支持输出多个数据 print("hello","world") 会输出两个内容,然后以空格分隔
sep: string inserted between values, default a space.
print("hello","world")
# hello world
print("a","b","c",1,[2],True,False)
# a b c 1 [2] True False
- 结束符号默认是换行
end: string appended after the last value, default a newline.
print("\n\n\n\n")
print("abc",end="") #换行符号为空,不会产生新行。因此abcdef为一行输出
print("def")
#abcdef
参数与参数之间的分隔符 sep默认是空格
sep: string inserted between values, default a space.
print('hello', 'world', sep='\n') # 这时hello world会分成两行输出
hello
world
print('hello', 'world', sep=' -----')
hello -----world
print('/home', 'user', 'documents', sep='/') # /home/user/documents
print('', 'home', 'user', 'documents', sep='/') # /home/user/documents
print(1, 'Python Tricks', 'Dan Bader', sep=',') # node -> child -> child
print('node', 'child', 'child', sep=' -> ') # 1,Python Tricks,Dan Bader
使用print输出小动画
import time
num_seconds = 3
for countdown in reversed(range(num_seconds + 1)):
if countdown > 0:
print(countdown, end='...')
time.sleep(1)
else:
print('Go!')
所以我们用print输出时,可以有很多种选项,不需要
print( "aaa" + str(1))
print("abc",1 ) #即可
猜你喜欢
- 2024-10-01 利用神经网络模型检测摄像头上的可疑行为
- 2024-10-01 使用神经网络的自动化特征工程(神经网络的特点及使用场景)
- 2024-10-01 Python基础学习必备的8个最常用的内置函数
- 2024-10-01 利用Click和argparse给你Python程序构建一个优雅的命令行界面
- 2024-10-01 langchain中的LLM模型使用介绍(llvm 分析)
- 2024-10-01 学习Python内置函数(range)来打印数学乘法表
- 2024-10-01 python3入门实例一:Hello World(python的hello world程序编写)
- 2024-10-01 python基础篇:讲讲python的内置函数一
- 2024-10-01 Python3中的print函数(python里的print函数)
- 2024-10-01 (39)python少儿编程之内建函数(python常用内建函数)
- 1518℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 603℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 522℃MySQL service启动脚本浅析(r12笔记第59天)
- 490℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 489℃启用MySQL查询缓存(mysql8.0查询缓存)
- 477℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 457℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 454℃MySQL server PID file could not be found!失败
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- windowsscripthost (69)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- c语言min函数头文件 (68)
- asynccallback (71)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)