基本数据类型int,bool,str
、基本数据类型(int,bool,str)
基本数据数据类型:
int 整数
str 字符串. 一般不存放大量的数据
bool 布尔值. 用来判断. True, False
list 列表.用来存放大量数据, []表示. 里面可以装各种数据类型.
tuple 元组. 只读列表. () 表示
dict 字典. {key:value}
set 集合. 不重复
1. int类型
bit_length() 返回一个数的二进制长度
2. bool类型
布尔只有两个值. True,False. 一般是没有什么操作的. 类型转换的问题:
想把xx转换成yy. yy(xx) 可以表示False的内容:0, "", list[], tuple(), 字典{}, None
所有的空都是False. 所有的非空是True 3. str类型 字符串
由',",''', """阔起来的内容就是字符串
字符串是不可变的数据类型.不论你执行任何操作. 源字符串是不会改变的, 每次操作都会返回新字符串 1. 索引和切片
索引从0开始, 使用[下标]可以获取到每一个字符, 还可以倒着数
切片: [起始位置:结束位置:步长]
1. 顾头不顾尾
2. 默认从左到右取值.
3. 当步长为负可以从右往左取值
[0:3] 0到3,不包括3
[0:]0到最后
2. 字符串相关操作
1. capotalize()首字母大写
2. upper()转换成大写
3. lower()转换成小写
4. strip()去掉空白
也可用于去掉指定元素 strip(" ")
5. replace(old, new) 把xxx替换成xxxx
6. split(" ") 切割. 返回列表. 用多长的刀. 就要损失掉多少
7. 查找
startswith()以...开头
endswith()以...结尾
find() 查找...的位置,没有返回-1
count()查找...出现的次数
index()索引位置
8. len() 字符串长度. python的内置函数
9.格式化输出
# 格式化输出
s12 = "我叫%s, 今年%d岁了, 我喜欢%s" % ('sylar', 18, '周杰伦') # 之前的写法
print(s12)
s12 = "我叫{}, 今年{}岁了, 我喜欢{}".format("周杰伦", 28, "周润发") # 按位置格式化
print(s12)
s12 = "我叫{0}, 今年{2}岁了, 我喜欢{1}".format("周杰伦", "周润发", 28) # 指定位置
print(s12)
s12 = "我叫{name}, 今年{age}岁了, 我喜欢{singer}".format(name="周杰伦", singer="周润发", age=28) # 指定关键字
print(s12)
10.判断
isalnum( )字母和数字
isalpha( )字母
isdigit( )数字
3. for循环
for 变量 in 可迭代对象:
循环体, 也存在break和continue
else:
当循环结束的时候会执行
基本数据类型int,bool,str的更多相关文章
- day3------基本数据类型int, bool, str,list,tuple,dict
基本数据类型(int, bool, str,list,tuple,dict) 一.python基本数据类型 1. int 整数. 主要用来进行数学运算 2. str 字符串, 可以保存少量数据并进 ...
- 第三天-基本数据类型 int bool str
# python基础数据类型 # 1. int 整数 # 2.str 字符串.不会用字符串保存大量的数据 # 3.bool 布尔值. True, False # 4.list 列表(重点) 存放大量的 ...
- 基本数据类型(int,bool,str)
目录: 1.int 数字类型 2.bool 布尔值 3.str 字符串类型 一.整型(int) 在python3中所有的整数都是int类型.但在python2中如果数据量 ...
- python中的基本数据类型(int,bool,str)及字符串操作
一. 基本数据类型概况 1. int 整数,主要用来进行数学运算 2. str 字符串,可以保存少量数据并进行相应的操作 3. bool 布尔值,判断真假,True,False 4. list ...
- python基本数据类型,int,bool,str
一丶python基本数据类型 1.int 整数,主要用来进行数学运算. 2.str 字符串,可以保存少量数据并进行相应的操作 3.bool 判断真假.True.False 4.list 存储大量数据, ...
- python基础知识梳理----3基本数据类型,int,bool,str ,for 循环,迭代
一:python的基本类型 1.int -----整数,主要进行数学运算 2.str -----字符串,可以保存少量数据,并进行相关操作, 3. bool ---布尔类型,判断真假 4.list ...
- 三.int , bool , str
03.万恶之源-基本数据类型(int, bool, str) 本节主要内容: 1. python基本数据类型回顾 2. int----数字类型3. bool---布尔类型4. str--- 字符串类 ...
- 关于int,bool,str
今日主要内容 基本数据类型(int,bool,str) 1.基本数据数据类型: int 整数 str 字符串. 一般不存放大量的数据 bool 布尔值. 用来判断. True, False list ...
- Python的基础类型(int,bool,str):
Python的基础类型(int,bool,str): 1.int -------> 整形:主要用力进行数字计算 2.string ------>字符串:可以保存少量数据并进行相关的操作 3 ...
随机推荐
- algorithm.sty not found error in LaTeX 解决方法
参考: algorithm.sty not found error in LaTeX algorithm.sty not found error in LaTeX 解决方法 错误日志: LaTeX E ...
- 51nod 1405 树的距离之和(dfs)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1405 题意: 思路: 先求出所有点到根节点的距离,需要维护每棵子树的大小 ...
- 51nod 1215 数组的宽度(单调栈)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1215 题意: 思路: 计算出以第i个数为最大值的区间范围,l_max[i ...
- python基础实践 -python是一门动态解释性的强类型定义语言
python是一门动态解释性的强类型定义语言 Python能做什么? Python是一门综合性的语言,你几乎能在计算机上通过Python做任何事情,以下是Python应该最广泛的几个方面: 1.网络应 ...
- _pvp_killed_loot
该表控制玩家被击杀时掉落物品,包括角色身上装备,背包物品,银行物品 comment 备注 entry 掉落的物品ID lootCount 掉落的物品数量 chance 掉落的几率,例如50,则50%几 ...
- EDCheckPrefabRef
using UnityEngine;using System.Collections;using UnityEditor;using UnityEngine.UI;using System.Refle ...
- ROC与AUC原理
来自:https://blog.csdn.net/shenxiaoming77/article/details/72627882 来自:https://blog.csdn.net/u010705209 ...
- STL——vector
学到STL的vector,发现手中的材料不是很详细,这里做个汇总. 1 操作 (1)头文件#include<vector>. (2)创建vector对象,vector<int> ...
- python Django 项目创建
注:后续如不特色说明,使用python版本均为python3 创建项目 django-admin startproject projectName 启动服务 python manage.py runs ...
- So you want to be a computational biologist?
So you want to be a computational biologist? computational biology course