python:第三章:hello world(3.11.6)

发布时间 2023-11-15 08:27:37作者: 刘宏缔的架构森林

一,linux上创建文件:

创建python文件,注意以.py为文件后缀

root@lhdpc:/data/python/tutorial/hello# vi hello.py

查看代码:

root@lhdpc:/data/python/tutorial/hello# more hello.py
print('hello, world')

执行python代码:

root@lhdpc:/data/python/tutorial/hello# python3 hello.py
hello, world

二,linux上交互环境

root@lhdpc:/data/python/tutorial/hello# python3
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello,world")
hello,world

说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/11/12/python-di-san-zhang-hello-world-3-11-6/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com

三,windows下执行python文件

1,用sublime text创建hello.py文件,保存到自定义的文件夹下,如图:

在命令行界面,用进入hello.py所在目录,执行,如图:

三,关于print函数

1,官方文档:

https://docs.python.org/zh-cn/3/library/functions.html#print

2,说明:

从文档可以看到,print是python内置的函数

它可以把它接收到的对象打印出来,

这里我们只需要知道它能把字符串打印到控制台就可以了

四,查看python的版本:

root@lhdpc:/data/python/tutorial/hello# python3 --version
Python 3.11.6