python基础学习-输入输出
来源:互联网 发布:网络大电影如何赚钱 编辑:程序博客网 时间:2024/05/17 23:35
python的基本输入是input(...)函数,但输入的都是字符串类型的,如果想输入其他类型的数据,就需要把输入的字符串类型的数据进行数据类型强转,比如输入"hello"就可以直接用input(...)直接进行输入
>>> string = input("please input a str:")
please input a str:hello
>>> print("input str is ",string)
input str is hello
而如果想要输入数字10的话就需要这样:
>>> number = input("please input a number:")
please input a number:10
>>> number = int(number)
>>> type(number)
<class 'int'>
>>> print(number)
10
基本输出是用print(...),可以一次性输出多个数据,中间用逗号隔开,比如输入hello world
>>> print("hello ","world")
hello world
然后就是格式化输入,使用format(...)函数
>>> print(format(12.3456,"4.2f"))
12.35
这里的4是占位的宽度,2是精度,如果宽度小于等于精度就左对齐,否则右对齐
>>> print(format(12.3456,"6.1f"))
12.3
百分数格式化输出,格式同上
>>> print(format(0.123456,"6.1%"))
12.3%
0 0
- python基础学习-输入输出
- python 基础学习1---输入输出
- Python基础-输入输出
- PYTHON-文件输入输出学习
- python学习-输入输出
- Python 学习之输入输出
- Python学习之:输入输出
- Python学习-1:输入输出
- Python学习笔记 输入输出
- Python学习之输入输出
- Python基础概念_9_输入输出
- Python基础入门之输入输出
- python学习之基本输入输出
- python学习笔记—输入输出
- python学习-文件的输入输出
- Python学习:输入输出重定向
- 【学习笔记】Python的输入输出
- Python基础(九)——输入输出
- 使用pod install发生的错误:[!] The 'XXX' target has frameworks with conflicting names: ummo
- Factorialize a Number
- UISearchController(使用、修改cancel文字)
- RabbitMQ~广播消息
- cookie和session的区别
- python基础学习-输入输出
- 从2段已序的数组中查找某一个数的算法
- 两个div右侧固定,左侧自适应屏幕
- I2C总线协议学习笔记
- 先存储逆序后的整数再输出
- 【RxJava】种下一棵树RxJava
- Android TelecomService的来电处理过程
- ubuntu下创建Eclipse快捷方式
- 《unix/linux编程实践教程》学习笔记:第二章 编写who,cp命令