python 中的第一个 hello world 程序输出

liftword7个月前 (12-14)技术文章114



程序运行:print("hello world")

我使用的是Python程序3.7.0 版本

介绍下print 概念

print 字面意思打印,将文本输出内容打印出来

输入: print("hello world")

输出:hello world


从源码可以看出为定义的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 做为Python中的使用的一个内定义的函数,可以直接使用

我们可以看下print的参数,

value: 值,可以传递多个值,通常需要打印的

sep : 用于将多个字符进行分割,默认一个空格

end : 用于行尾结束符,默认为回车换行

file : 用于输出的文件,默认为sys.stdout,标准输出, 这里的sys.stdout不过多讲

flush :简单讲将缓存里面的内容立即输出到标准输出流(这里是sys.stdout, 也就是默认的显示器)

相关文章

Python自动操作 GUI 神器——PyAutoGUI

作者:闲欢来源:Python 技术我们以前讲过怎样使用 Python 在浏览器中实现页面自动化操作,不管用哪种方式实现,都是通过定位页面中的元素来进行相应的操作。今天我们来聊一聊如何在桌面实现自动化操...

「零基础学Python」输出函数print()如何使用?

(一)print()函数的作用:可以将想要展示的内容在IDLE或标准控制台上显示。例如:print(520):(1)向计算机发出指令打印520。(2)把代码编译成计算机能听懂的机器语言。(3)做出相应...