Python,二 运行第一个Python程序

1. 输出

# output
print()
print("hello world")
print("hello","willow","output")
print("100 + 200 = ",100+200)
print(100+200)

2.输入

# input
name = input()
name
print(name)
name = input("please enter your name:")
print("hello,",name)

3.代码块

代码块用:和四个空格的缩进来体现

# print absolute value of a int
a = 100
if a>=0:
    print(a)
else:
    print(-a)

4.保存与运行

在Python命令行交互环境下,只能输入一行代码,执行一行。无法保存和再次运行,如果想要再次运行就需要再次输入相同的代码,怎么办呢?

我们可以选择一种文本编辑器,例如:sublime Text,将代码书写进去后,保存为.py的文件;然后进入cmd 命令行

1)进入 .py 文件保存的文件夹下

2)more + *.py 可以看到文件中全部内容

3)python + *.py 执行这个文件

Ps:在Windows下.py文件是没有办法像.exe文件一样,双击运行的,必须通过上面的步骤。python的Idle也没有作用。