character string , list , Tuples , Mutual transformation and difference between sets .
str1 = 'helloworld'
print(str1)
# String to list ,list()
list1 = list(str1)
print(list1)
# String to tuple ,tuple()
tup = tuple(str1)
print(tup)
# List tuple
tup1 = tuple(list1)
print(tup1)
# String conversion ,set()
set1 = set(str1)
print(set1)# There are no duplicate elements in the set
# List to set
set2 = set(list1)
print(set2)
# Tuple to set
set3 = set(tup)
print(set3)
helloworld
['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']
('h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd')
('h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd')
{
'd', 'o', 'e', 'h', 'r', 'l', 'w'}
{
'd', 'o', 'e', 'h', 'r', 'l', 'w'}
{
'd', 'o', 'e', 'h', 'r', 'l', 'w'}
Data type comparison character string list Tuples Dictionaries aggregate
Is it orderly yes yes yes no no
Modifiable or not no yes No yes yes
Variable type and immutable type
Variable type , Values can change :
Immutable type , Value cannot be changed :