Learning Python 002 print() 和 input()
2016-07-14 17:43
465 查看
Python print() 和 input()
print()函数
print()函数可以向终端中输入指定的内容。
输出当个字符串
.py文件中,输入下面的代码,并保存:
print('hello world')
> demo.py hello world
终端中执行:
>>> print('hello world')
hello world
输出多个字符串
.py文件中,输入下面的代码:
print('Aobo', 'Sir', 'Learning', 'Python')
> demo.py ('Aobo', 'Sir', 'Learning', 'Python')
终端中执行:
>>> print('Aobo', 'Sir', 'Learning', 'Python')
Aobo Sir Learning Python
在Python的交互模式,print()会依次打印每个字符串,遇到逗号“,”会输出一个空格。
在Python的.py文件模式,print()会打印出除print这个函数名之外的所有的信息。
.py文件中,输入下面的代码:
print('32 + 32 =', 32+32)
> demo.py ('32 + 32 =', 64)
终端中执行:
>>> print('32 + 32 =', 32+32)
32 + 32 = 64
input()函数
在.py文件中输入下面的代码:
name = input('What\'s your name?') print('Hello, ' + name + '!')
>demo.py What's your name? :
你输入的内容,需要用引号括上。
What's your name? : 'AoboSir' Hello, AoboSir!
终端中执行:
>>> name = input('What\'s your name?') What's your name? :
输入你的名字:(不需要被引号括上)
What's your name? : AoboSir Hello, AoboSir!
相关文章推荐
- Python基础语法
- 用python写一个简单的推荐系统
- 完全理解Python迭代对象、迭代器、生成器
- Python解析excel文件并存入sqlite数据库
- python笔记 - day4-之装饰器
- python简要
- Python 库大全
- 详解Python中re.sub
- 习题5 更多的变量和打印
- scrapy抓取csdn中标题带有“语义”关键字的文章的标题和链接
- Python.Lists
- python制作二维码
- Python实现Singleton模式
- Python 面向对象编程容易忽视的知识点
- Zen of Python
- [python]去掉 unicode 字符串前面的 u(转)
- 习题4 变量和命名
- Learning Python 001 第一个程序
- Learning Python 001 第一个程序
- consul python api