1.编写第一个python程序,使其运行时输出“Hello,world!”
- 使用命令行工具运行程
首先新建一个文本文件,并输入以下代码,再将文本保存为hello_world.py
print("Hello,world!")
打开cmd,进入该文本所在文件夹,输入如下指令
C:\Users\Administrator>cd C:\Users\Administrator\Desktop
C:\Users\Administrator\Desktop>python hello_world.py
Hello,world!
2.用 Python 交互式解释器执行加法、减法、乘法、除法、三角函数等常见的数学运算
要先导入math模块,才能使用三角函数
>>> 46%8
6
>>> 6*4
24
>>> 7^2
5
>>> 9-10
-1
>>> import math
>>> math.cos(math.pi/3)
0.5000000000000001
>>> math.sin(math.pi/2)
1.0
>>> math.degrees(math.pi/6)
29.999999999999996
>>> math.radians(180)
3.141592653589793