python初级 1 数据类型和变量
2018-01-14 12:40
459 查看
一、整数(int)
例: 0 1 2 3 -1 -2 –3In [31]: print(type(0))
<class 'int'>
In [32]: print(type(1))
<class 'int'>
In [33]: print(type(2))
<class 'int'>
In [34]: print(type(3))
<class 'int'>
In [35]: print(type(-1))
<class 'int'>
In [36]: print(type(-2))
<class 'int'>
In [37]: print(type(-3))
<class 'int'>
二、浮点数(小数)(float)
例:0.0 0.3 15.5 1.0 –1.45In [39]: print(type(0.0))
<class 'float'>
In [40]: print(type(0.3))
<class 'float'>
In [41]: print(type(15.6))
<class 'float'>
In [42]: print(type(1.0))
<class 'float'>
In [43]: print(type(-1.45))
<class 'float'>
三、字符串(str)
指的是””或是’’里面的内容例:'2a' "33" "ab\'cd"
In [44]: print(type('2a'))
<class 'str'>
In [45]: print(type("33"))
<class 'str'>
In [46]: print(type("ab\'cd"))
<class 'str'>
In [48]: print("2a")
2a
In [49]: print("33")
33
In [50]: print("ab\'cd")
ab'cd
如果想表示’或是”时,需要采用转义符\, 如果需要表示\时,在外面加上转义符\
例:"I\'m a boy" "say \"hello world\"" "print \\"
In [51]: print("I\'m a boy")
I'm a boy
In [52]: print("say \"hello world\"")
say "hello world"
In [53]: print("print \\")
print \
四、布尔值(bool)
例:True, FalseIn [56]: print(type(True))
<class 'bool'>
In [57]: print(type(False))
<class 'bool'>
五、空值(NoneType)
例:NoneIn [58]: print(type(None))
<class 'NoneType'>
练习
请打印出以下变量的值:n = 123
f = 456.789
s1 = 'Hello, world'
s2 = 'Hello, \'Adam\''
s3 = r'Hello, "Bart"'
s4 = r'''Hello, Lisa!'''
相关文章推荐
- day①:python的变量及数据类型
- Python(二)基本数据类型和变量
- Python(2)python中的注释,语句分类,变量,数据类型,多进制书写规则
- python数据类型与变量
- Python 判断变量的数据类型
- python基础之数据类型与变量
- 1.Python进阶-Python变量与数据类型
- Swift初级:变量与数据类型
- 变量和简单数据类型(Python)
- Python笔记——基本语法:标识符、数据类型、变量、运算符及表达式/编码风格
- Python学习 第4天 基本语法-变量、数据类型、运算符、流程控制
- Python学习日志 - 2.变量和简单数据类型(习题解答)
- python学习(一)变量和数据类型
- Python数据类型和变量
- Python学习笔记(二)--变量和数据类型
- python 数据类型跟变量
- 学习Python的基础,Python的数据类型和变量
- python:(2)数据类型和变量
- python入门(8)数据类型和变量
- python每日一小记(1)--数据类型和变量