编写第一个Python程序:“Hello world”
编写第一个 Python 程序:“Hello world”。
虽然有效代码只有:print(”hello world”)。
但注意,你需要尝试至少三种不同的运行方法:
1. 在命令行直接运行;
2. 编写一个 Python 文件,将 print hello world 封装为一个函数,通过 main 函数调用它来运行;
3. 编写一个 class,将 print hello world 封装为一个 method,通过 main 函数创建class 实例来运行 method。
现在只会第一种运行方法,要是会了以后再更
1. 定义函数def,
>>> def hello():
print("Hello World!")
>>> hello()
Hello World!
2.在命令行直接运行有效代码
>>> print("Hello World!")
Hello World!
3.新建文件,在文件中运行代码