整型:

  type():显示数据类型

# 整型,int
# python3里,不管数字有多大,都是int类型
# python2里,有大小区分,长整型:long int
a = ""
print(type(a),a) b = int (a)
print(type(b),b)
#进制转换
num = "d"
v = int (num, base=16)
print(v)

#当前数字用二进制的位数表示
age = 4
r = age.bit_length()
print(r)

字符型:

#索引
test = "alexalex"
v = test.find("xa")
print(v)

占位符

test = 'i am {0},age {1}'
v = test.format('alex',12)
print(v)

test.format_map({"name":'alex',"a":19})

#字符串中是否只包含字母和数字
test = "abc123"
v = test.isalnum()
print(v)
#制表符
s = "username\temail\tpassword\nzhangsan\tzhang@qq.com\t123\nzhangsan\tzhang@qq.com\t123\nzhangsan\tzhang@qq.com\t123"
v = s.expandtabs(20)
print(v)

#判断是否为字母,汉字
test = "jing"
v = test.isalpha()
print(v)
#判断字符串是否为数字
test = "Ⅱ"
v1 = test.isdecimal() #支持123
v2 = test.isdigit() #支持②,123
v3 = test.isnumeric() #支持 三,②,Ⅱ,123
print(v1,v2,v3)
#字母,数字,下划线:标识符
#判断是否为标识符
test = "_jfgh"
v = test.isidentifier()
print(v)
#判断是否存在不可显示的字符
#\t 制表符
#\n 换行符
test = "you are"
v = test.isprintable()
print(v)
#判断是否全部是空格
test = " "
v = test.isspace()
print(v)
test = "you are a man"
v1 = test.title() #转换为标题
print(v1)
v2 = v1.istitle() #判断是否为标题
print(v2)
# 将字符串中的每个元素按照指定分隔符进行拼接
test = "清风明月两岸绿"
print(test) #清风明月两岸绿
t = ' '
v = t.join(test) #清 风 明 月 两 岸 绿
print(v)
#填充
test = 'alex'
v1 = test.ljust(10,"@") #alex@@@@@@
v2 = test.rjust(10,"@") #@@@@@@alex
print(v1,v2)
#判断是否全部为大小写 和 转换为大小写
test = "Alext"
v1 = test.isupper()
v2 = test.upper()
print(v1,v2) v3 = test.islower()
v4 = test.lower()
print(v3,v4)
#去除左右空格,换行
test = "allell"
v1 = test.lstrip()
v2 = test.rstrip()
v3 = test.strip() #从指定的字符串中去除原文中左右子序列
#指定字符中有几个字符就在原文中找几个字符
x1 = test.lstrip("ex")
x2 = test.rstrip("fl")
x3 = test.strip("ax")
print(x2)
#替换对应关系
test1 = "abcd"
test2 = ""
v = "fbgyuewt;dkfobgdsc"
m = str.maketrans(test1,test2)
new_v = v.translate(m) # f2gyuewt;4kfo2g4s3
print(new_v)
test = "testghsjghfsf"
#分成三份
v1 = test.partition("s") #('te', 's', 'tghsjghfsf')
v2 = test.rpartition("s")
#遇到指定字符全部分割
v3 = test.split("s")
v4 = test.rsplit("s") #['te', 'tgh', 'jghf', 'f']
print(v1)

最新文章

  1. UVA - 1025 A Spy in the Metro[DP DAG]
  2. Oracle中查看所有表和字段以及表注释.字段注释
  3. python处理经过gzip压缩的网页内容
  4. NYOJ 16 矩形嵌套(经典动态规划)
  5. Kafka 分布式消息队列介绍
  6. MergeSort(归并排序)算法Java实现
  7. Qt移植 Window --Linux
  8. SQL通用函数-nvl-nvl2 -nvlif-nullif-coalesce-decode-case
  9. 强大的微软Microsoft Translator翻译接口
  10. sqldeveloper连接mysql
  11. python中shutil模块的使用
  12. Atitit.如何文章写好 论文 文章 如何写好论文 技术博客
  13. Android开发之Activity
  14. pytest+allure+jenkins +python2.7
  15. 阿里巴巴Java开发规约插件全球首发!(转)
  16. Nginx Location模块
  17. 洛谷 1.5.1 Number Triangles 数字金字塔
  18. vue打包体积优化之旅
  19. 用sublime server 启动本地服务器(手机访问电脑页面)
  20. (转)SSH服务详解

热门文章

  1. CF #487 (Div. 2) D. A Shade of Moonlight 构造_数形结合
  2. [NOIP补坑计划]NOIP2017 题解&做题心得
  3. centos7最小化安装图形界面
  4. 从YV12到NV12
  5. 前端通过canvas实现图片压缩
  6. 【Codeforces Round #499 (Div. 2) E】Border
  7. Android px,dp,pt,sp的差别
  8. hdu 4966 最小树形图
  9. centos6高速部署java应用
  10. ThinkPHP5.0框架开发--第5章 TP5.0 控制器