python int str
1. int 类型转换
a = "123"
b = int(a)
b = b+10
print(type(a),a)
print(type(b),b)
2. int(num,base=2), base不写的时候默认为10
a = "0011"
b = int(a,base=2)
print(b)
答案为 3.
3. -.bit_length() 当前数字为2进制时,至少要用多少位来表示
a = 8
b = a.bit_length()
print(b)
answer:4
4. str 居住 center()
a = "kkkk"
b = a.center(20,"&")
print(b)
#"&"中只能填一个 &&&&&&&&kkkk&&&&&&&&
5. str 之count()计数
count(self, sub, start=None, end=None)
a = "kkkkrrrrrrrrrxxxxxxxxx"
b = a.count('r',5,14)
print(b) 8
6. find(self, sub, start=0, end=_sys.maxsize) 比index()好用
a = "djalskfjs;kd k"
b = a.find("ja",0,20)
print(b) 1
7. format(self, *args, **kwargs ) 两种方式效果一样
a = 'jkldak{ff},ioeu{gg}'
b = a.format(ff='JOAN',gg='HUMAN')
print(b)
a = 'jkldak{0},ioeu{1}'
b = a.format('JOAN','HUMAN')
print(b)
jkldakJOAN,ioeuHUMAN
8. format_map(self, mapping)
format_map(self, mapping): # real signature unknown; restored from __doc__
9. def isalnum(self, *args, **kwargs): # real signature unknown
Return True if the string is an alpha-numeric string, False otherwise.
python int str的更多相关文章
- 【python】python各种类型转换-int,str,char,float,ord,hex,oct等
[python] int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) ...
- python基础-2 编码转换 pycharm 配置 运算符 基本数据类型int str list tupple dict for循环 enumerate序列方法 range和xrange
1.编码转换 unicode 可以编译成 UTF-U GBK 即 #!/usr/bin/env python # -*- coding:utf-8 -*- a = '测试字符' #默认是utf-8 a ...
- Python学习笔记之基础篇(三)python 数据类型 int str bool 详谈
python 的数据类型: 1.int:存放 1,2,3 等数据 ,用于数字的运算 2.bool :True, False 用于判断 3.str:字符串,用来存储少量的数据 4.list : 数组的 ...
- 嵌入式 python之str操作
1.字符串的对齐方式:①:center(int[,str])>>> string = 'Fishhat'>>> string.center(55)' ...
- python int异常 python isdigit
python int是python把任何类型转换成int类型的方法,但是你如果运用不好的话,会引发异常,但是python的str字符串转换方法运用起来倒是比较安全,它把任何对象转换成字符串类型都不会报 ...
- 基础数据类型(int,str,bool)
一 python 中的基础数据类型 1.int 数字类型(整数类型) 主要用来数学计算 2.str 字符串 可以保存少量数据进行操作 3.bool 布尔值 判断真假 True Fa ...
- Python - int()
参考 https://docs.python.org/3/library/functions.html?highlight=int#int If x is not a number or if bas ...
- Python之str()与repr()的区别
Python之str()与repr()的区别 str()一般是将数值转成字符串,主要面向用户. repr()是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思.如list, ...
- python的str,unicode对象的encode和decode方法
python的str,unicode对象的encode和decode方法 python中的str对象其实就是"8-bit string" ,字节字符串,本质上类似java中的byt ...
随机推荐
- 基于Docker搭建MySQL多源复制环境
MySQL5.7在主从复制上面相对之前版本多了一些新特性,包括多源复制.基于组提交的并行复制.在线修改Replication Filter.GTID增强.半同步复制增强等. 多源复制:多源复制加入了一 ...
- Python socket文件传送md5校验
soket_server import socket,os,hashlib server = socket.socket() server.bind(('0.0.0.0',9999)) server. ...
- maven maven-war-plugin 解决java war项目间的依赖(两个war都可独立部署运行,maven 3.2.x亲测)
最近整理基础框架,有些项目不想分布式,所以基础框架必须同时可独立部署,也可直接被作为依赖和业务工程打到一起,记录下解决war项目依赖的要点,一开始用warpath,结果报找不到,有些帖子还是17年的, ...
- web前端除了关注代码功能实现,还应具备web性能优化以及SEO优化的常识
web前端除了关注代码功能实现,还应具备web性能优化以及SEO优化的常识 ——不会WPO.SEO的前端工程师不是好码农 作为一名web前端工程师,除了要实现上级的要求,满足其所需要的功能,还要在平时 ...
- 修改SS配置文件使其同时支持IPV4和IPV6网络
将/etc/shadowsocks-libev/config.json文件中的 "server":"0.0.0.0", 修改为: "server&qu ...
- (转)GANs and Divergence Minimization
GANs and Divergence Minimization 2018-12-22 09:38:27 This blog is copied from: https://colinraff ...
- linux中搭建vue-cli
1 安装nvm依赖并配置环境变量在 sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh ...
- js获取当前时间:封装js的日期时间
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- hello1
1:选择hello1文件夹并单击“打开项目”.展开“Web页”节点,然后双击该index.xhtml文件以在编辑器中查看它. 该index.xhtml文件是Facelets应用程序的默认登录页面.在典 ...
- RMAN 的优缺点及RMAN 备份及恢复步骤
一. RMAN 备份的一些优点和OS命令备份方式相比,使用RMAN的优点 1 备份执行期间不需要人工干预,因此减少了误操作的机会:2 可以有效的将备份和恢复结合起来:3 支持除逻辑备份以外的所有 ...