1、str类型转int类型,字符串与整形互转
>>> a = '10'
>>> b = int(a)
>>> print(type(a))
>>> print(type(b))
2、将str字符串转换成列表list
>>> Test_str = "python was created in 1989,python is using in AI,big data,IOT."
>>> newTest_str = list(Test_str)
>>> print(type(Test_str))
>>> print(type(newTest_str))
3、将str字符串转换成字典dict(json规定,数组或对象之中的字符串必须是用双引号,不能用单引号)
>>> test = '{"name": "linda", "age": "18"}'
>>> test_dict = json.loads(test)
>>> print(type(test))
>>> print(type(test_dict))
4、将str字符串转换成set
>>> geeks = "geeks"
>>> print(str(type(geeks)))
>>> set_geeks = set(geeks)
>>> print(type(set_geeks))
5、列表list转换成字符串str(list [ ] 中包含的元素是str " "类型)
>>> list_str1= ["你好","hello","world"]
>>> list_str2="".join(list_str1)
>>> print(list_str2)
你好helloworld
6、列表list转换成元组tuple
list1 = ['a', 'b', 'c']
var2 = tuple(list1)
print(var2)
7、嵌套元组tuple转换字典dict
a = (("name", "lisa"), ("sex", "nale"))
var3 = dict(a)
print(var3)
8、把元组(1,2,3,4,5,6)元素格式化成字符串
tupl = (1, 2, 3, 4, 5, 6)
new = f"{tupl}"
new1 = "{0}".format(tupl)
print(new)
print(type(new))
9、将字典dict转化为字符串str
b = {"name": "linda", "age": "18"}
str_b = repr(b)
print(str_b[0:3])
10、字典转json使用:json.dumps()
11、json转字典使用:json.loads()