python数据类型之字符串与int,float,bool

#coding=utf-8;
#1.字符串与int相互转换
a=100;
b=str(a);
c="200";
d=int(c);
print type(a),a,type(b),b,type(c),c,type(d),d;
#2.字符串与float相互转换
a1=1.23
b1=str(a1);
c1="2.567";
d1=float(c1);
print type(a1),a1,type(b1),b1,type(c1),c1,type(d1),d1;
#3.字符串与bool相互转换
a2=True;
b2=str(a2);
c2="False";
d2=bool(c1)
print type(a2),a2,type(b2),b2,type(c2),c2,type(d2),d2;

运行结果:

<type 'int'> 100 <type 'str'> 100 <type 'str'> 200 <type 'int'> 200
<type 'float'> 1.23 <type 'str'> 1.23 <type 'str'> 2.567 <type 'float'> 2.567
<type 'bool'> True <type 'str'> True <type 'str'> False <type 'bool'> True

 

posted @ 2022-11-07 15:43  家乐福的搬砖日常  阅读(54)  评论(0编辑  收藏  举报