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

liftword5个月前 (12-14)技术文章71



程序运行: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 之 openpyxl 库 设置 Excel 单元格自动换行,自动对齐

openpyxl 写入数据到 Excel 单元格中,设置自动换行,以及设置左对齐,设置上中下的居中对齐...