python-009基本数据类型常用功能(详解)
Posted bigdata-6
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-009基本数据类型常用功能(详解)相关的知识,希望对你有一定的参考价值。
1 基本数据类型常用功能: 2 数字 int 3 n1 = 2 4 n2 = 3 5 print (n1 + n2) 6 print (n1.__add__(n2)) 7 8 9 # 获取二进制的最短位数 10 # i = 4 11 # ret = i.bit_length() 12 # print (ret) 13 14 字符串 str 15 1.capitalize 16 a1 = ‘alex‘ 17 rex = a1.capitalize() 18 print (rex) 19 2.center(self, width, fillchar=None) 20 width:总长度;fillchar:空白处填充内容 21 a1 = ‘alex‘ 22 rex = a1.center(20, ‘*‘) 23 print (rex) 24 25 3.count:查看子序列的个数 26 a1 = ‘alex is fskfdj‘ 27 rex = a1.count(‘s‘) 28 print (rex) 29 4.指定范围内,某个值出现的次数 30 a1 = ‘alex is fskfdj‘ 31 rex = a1.count(‘f‘,0,12) 32 print (rex) 33 34 5.endswith:是否以 ***结束 35 a1 = ‘alex‘ 36 rex = a1.endswith(‘x‘) 37 print (rex) 38 6.从0开始,小于2的值 39 a1 = ‘alex‘ 40 rex = a1.endswith(‘l‘,0,2) 41 print (rex) 42 43 7.find:寻找子序列的位置,如果没有找到,返回-1 44 a1 = ‘alex‘ 45 rex = a1.find(‘g‘) 46 print (rex) 47 48 8.format:字符串格式化,动态参数 49 a1 = ‘helle {0} ,age (1)‘ 50 print (a1) 51 # {0},{1} 是占位符 52 new1 = a1.format("alex",19) 53 print (new1)
基本数据类型常用功能:数字 intn1 = 2n2 = 3print (n1 + n2)print (n1.__add__(n2))
# 获取二进制的最短位数# i = 4# ret = i.bit_length()# print (ret)
字符串 str1.capitalizea1 = ‘alex‘rex = a1.capitalize()print (rex)2.center(self, width, fillchar=None) width:总长度;fillchar:空白处填充内容a1 = ‘alex‘rex = a1.center(20, ‘*‘)print (rex)
3.count:查看子序列的个数a1 = ‘alex is fskfdj‘rex = a1.count(‘s‘)print (rex)4.指定范围内,某个值出现的次数a1 = ‘alex is fskfdj‘rex = a1.count(‘f‘,0,12)print (rex)
5.endswith:是否以 ***结束a1 = ‘alex‘rex = a1.endswith(‘x‘)print (rex)6.从0开始,小于2的值a1 = ‘alex‘rex = a1.endswith(‘l‘,0,2)print (rex)
7.find:寻找子序列的位置,如果没有找到,返回-1a1 = ‘alex‘rex = a1.find(‘g‘)print (rex)
8.format:字符串格式化,动态参数a1 = ‘helle {0} ,age (1)‘print (a1)# {0},{1} 是占位符new1 = a1.format("alex",19)print (new1)
布尔型 bool列表 list元祖 tuple字典 dict
以上是关于python-009基本数据类型常用功能(详解)的主要内容,如果未能解决你的问题,请参考以下文章