2019-07-09
阅读量:
522
如何将字符转换为字典或复数
1. dict():此函数用于将顺序元组(键,值)转换为字典。
2. str():用于将整数转换为字符串。
3. complex(real,imag)::此函数将实数转换为复数(实数,图像)数。
# Python code to demonstrate Type conversion
# using dict(), complex(), str()
# initializing integers
a = 1
b = 2
# initializing tuple
tup = (('a', 1) ,('f', 2), ('g', 3))
# printing integer converting to complex number
c = complex(1,2)
print ("After converting integer to complex number : ",end="")
print (c)
# printing integer converting to string
c = str(a)
print ("After converting integer to string : ",end="")
print (c)
# printing tuple converting to expression dictionary
c = dict(tup)
print ("After converting tuple to dictionary : ",end="")
print (c)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论