MOOC的Python笔记(二)python数据类型与输入输出
来源:互联网 发布:神通数据库 ceil 编辑:程序博客网 时间:2024/05/16 17:05
python的输入是使用input函数,<变量>=input(<提示性文字>)
例如:val=input ("please input a temperature like 32C :")
界面输出
please input a temperature like 32C :
等待你的输入,你输入的东西会赋值给val,python是脚本语言,所以变量都是弱类型的。
但是弱类型的语言也是有数据类型的,如下
1、字符串
2、布尔类型
3、数字
4、列表
5、元组
6、字典
7、日期
(4~7这篇博文暂时不详细说,后面在用一篇博文说)
1、字符串(默认编码方式为 UTF-8)
如何在Python中使用字符串
a、使用单引号 '
str='this is string'
b、使用双引号 "
双引号中的字符串与单引号中的字符串用法完全相同
str="this is string"
c、使用三引号 '''
利用三引号,表示多行的字符串,可以在三引号中自由的使用单引号和双引号,例如:
str='''this is string
this is pythod string
this is string'''
2、布尔类型
False、True
3、数字
包括整数、浮点数。
a=1
b=2.3
删除一个变量使用 del
例如:
del a
python的输出是使用print格式化输出
格式化输出需要用%来做变量的占位符
字符串 %s
整型 %d
浮点型 %f
浮点型 %.2f 指定保留小数点后2位数
例如:
print("hello world")#输出 hello world
print("%s" %("hello world"))#输出 hello world
h="hello world"
print(h)#输出 hello world
f=2.33
print("Converted temperature is %f F"%f)
print("Converted temperature is %.2f F"%f)
输出
Converted temperature is 2.330000F
Converted temperature is 2.33F
- MOOC的Python笔记(二)python数据类型与输入输出
- MOOC的Python笔记(四)元组与列表
- python学习笔记(一)运行,输入输出,数据类型
- MOOC的Python笔记(一)基本语法
- MOOC的Python笔记(五)文件操作
- (二)python的数据类型与运算符
- 【学习笔记】Python的输入输出
- python学习笔记二数据类型
- Python学习笔记(二)——IO输入输出
- 我的Python学习之路 Python的输入输出与基本数据类型
- python数据类型(二)
- python数据类型(二)
- python 南京大学MOOC学习笔记
- Python数据分析与展示(二)(基于北理MOOC)
- Python 起步一 输入输出,数据类型
- 输入输出,数据类型,python编码问题
- python——数据类型,输入输出
- python学习-Day6-python的数据类型(二)
- Scrapy-Splash爬取淘宝排行榜(一)
- JNDI理解
- Java多线程通信方式
- 1055. 集体照 (25)
- SDUT 2411:Pixel density
- MOOC的Python笔记(二)python数据类型与输入输出
- 对Gson解析的理解
- SDUT 2413:n a^o7 !
- java基础笔记04
- C语言
- DigCtr TJ
- centos下配置LNMP环境(源码安装)
- 浅析Java中CountDownLatch用法
- 分治:幂乘算法