首页 技术 正文
技术 2022年11月12日
0 收藏 450 点赞 4,902 浏览 1733 个字

整型:

  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)

python学习(二):基本数据类型:整型,字符型

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

python学习(二):基本数据类型:整型,字符型

字符型:

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

占位符

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

python学习(二):基本数据类型:整型,字符型

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)

python学习(二):基本数据类型:整型,字符型

#判断是否为字母,汉字
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)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,129
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,601
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,444
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,218
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,852
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,940