以下通过Linux命令行模式编写运行Python,粗体表示用户输入信息。
charles@charles:~$python3.5 # Linux提供的命令行模式
Python 3.5.2 (default, Aug 31 2016, 10:51:09)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>100+200 # Python交互式环境
300
>>>print("hello world")
hello world
>>>exit()
charles@charles:~$vim hello.py
100+200
print("100 + 200 =", 100+200) # 逗号“,”输出一个空格
print("hello world")
charles@charles:~$python3.5 hello.py
100 + 200 = 300
hello world
charles@charles:~$vim hello_name.py
name = input("Please input your name : ") # 输入变量
print("hello", name) # 输出变量
charles@charles:~$python3.5 hello_name.py
Please input your name :charles
hello charles
或者
charles@charles:~$vim hello_name.py
#!/usr/local/python/bin/python3.5
name = input("Please input your name : ")
print("hello", name)
charles@charles:~$chmod u+x hello_name.py
charles@charles:~$./hello_name.py
Please input your name :charles
hello charles