Python3学习 Day1

notebook 为 Anacond3

数据类型

1、Integer (int) 2、Float (float) 3、Boolean (bool) 4、String (str)

1、int(整型)

image.png

//:取整,计算出来的结果为整数

image.png /:计算出来的结果为Float,带小数 image.png %:取余 image.png

可用type()查看对应的数据类型 image.png image.png

注:在 Python2 中,int 的大小限制为 32 位,这足够存储从 -2,147,483,648 到 2,147,483,647 的整数。long 可以存储 64 位。超过这个范围的整数会导致 整数溢出。 在 Python3 中,一个 int 可以处理任意大的整数,不会导致溢出。

2、Float(浮点)

image.png

Math 函数 Python 还提供了很多有用的数学函数,都包含在 math 包里。要使用它们,需要先 import math。 image.png image.png image.png image.png

3、Boolean(布尔类型)

image.png

4、String(字符串)

字符串的三种表示 1、单引号 s = 'this is a string' 2、双引号 str = "this is also a string" 3、三单引号/三双引号 image.png

目前看只有这个形式才能在不加 \n 的情况输出时直接换行?

类型转换

image.png image.png

合并、复制

image.png

提取和切片

1、提取单个字符串

image.png

2、提取子字符串

Format: [start🔚step] [:] 提取所有字符串 [start:] 从start到尾 [:end] 从头到end-1 [start:end] 从start到end-1 [start🔚step] 从start到end - 1, 每隔step-1取一次 image.png

获取字符串的长度

image.png

分离和合并

spilt()返回的是一个list image.png

替换

image.png

格式

image.png

其他用法

image.png

0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP