单个字符串输出
命令如下
>>> print('hello world')
hello world
多个字符串输出
>>> print('hello world')
hello world
数学运算输出
>>> print('1 + 1 = ', 1 + 1)
1 + 1 = 2
>>> print('1 - 1 = ', 1 - 1)
1 - 1 = 0
>>> print('1 * 2 = ', 1 * 2)
1 * 2 = 2
>>> print('1 / 2 = ', 1 / 2)
1 / 2 = 0.5
输入 input()
- 输入name = input(),这里的name可以认为是变量
- 然后写入任意字符串例如“Sufadi”
- 然后输入name,这里就可以打印出被赋值后的变量
>>> name = input()
Sufadi
>>> name
'Sufadi'
输入与输出小demo
- 建立一个helloworld.py的文件
- 代码如下
“`
print(‘Please input your name’)
name = input()
print(‘hello world’, name)
3. cmd窗口运行 python helloworld.py
4. 运行结果
D:\PythonProject>python helloworld.py
Please input your name
sufadi
hello world sufadi
“`
本文通过一个简单的Hello World程序介绍了Python的基本语法,包括字符串输出、基本数学运算、变量定义及使用input()函数获取用户输入等内容。
2990

被折叠的 条评论
为什么被折叠?



