day02
##
1、基本数据类型(python 相比其他语言,简化数据类型)
- 数字 (整型int 浮点型float)
- 布尔 (只有2个值:True/False)
- 字符串
- 列表 (list)
- 元组 (tuple)
- 集合 (set)
- ## 数字
-
type(1+1) //int type(1+1.0) //float type(1*1) //int type(1*1.0) //float type(2-1) //int type(2-1.0) //float type(2/1) //float type(2//1) //int type(2//1.0) //float /代表除法(得到float) //代表整除
## 进制 —— 表示与转换
-
二进制: 0b10/0b110 八进制: 0o10/0o170 十六进制: 0x2A/0x49 转二进制: bin(0xA1) 转十进制: int(0b1110) 转八进制: oct(10) 转十六进制: hex(0o777) - ###布尔
- 布尔类型其实归类到数字类型下的,
只有2个值:True、False (第一个字母大写) - 转数字
-
// 转数字
int(True) //1 int(False) //0// 转布尔
bool(2) //True bool(-1.1) //True bool(0.0) //False bool('wt') //True bool('') //False bool([1,2]) //True bool([]) //False bool({1,2,3})//True bool({}) //False bool(None) //False###字符串
-
单引号: 'hello world' 双引号: "hello world" 三引号: '''leffodfdfdsds''' (多行文本) --------单双引号也可以实现多行文本,每行结尾使用\ - #运算 、
-
//1、拼接 'hello'+'world' //2、重复 'hello'*3 //3、截取某一个字符 'helloworld'[1] //e 'helloworld'[-3] //r 从字符串末尾开始数 //4、截取某段字符 'helloworld'[0:4] //hell 'helloworld'[0:-1] //helloworl 'helloworld'[2:] //lloworld 'java python c++ php ruby'[-4:] //ruby 'java python c++ php ruby'[:-4] //java python c++ php //5、获取字符串长度 len('helloworld') //10
记录平时的一些小问题~
或转载一些小知识点
学习学习

浙公网安备 33010602011771号