11. The container of cast data _

# ### casts container type data (STR SET dict List tuple) 
 
# STR turn into strong string type 
# (data container types / Number of data types are) 
var1 = "happy every day" 
var2 = [. 1, 2,3] 
var3 = (4,5,6) 
var4 = { "beautiful", "store name personal"} 
var5 = { "A":. 1, "B": 2, "C":}. 3 
var6 = 123 
 
 
 
strong # string rotation law: is pure in quotation marks on both sides of the original data 
RES = STR (var2) 
RES = STR (var3) 
RES = STR (var5) 
RES = STR (var6) 
# Print (RES, type (RES )) 
# repr string of the output data of the prototype (see quotes like with repr conversion) 
Print (repr (RES), type (RES)) 
 
# list strong law transfer list: 
'' ' 
If a string: the character each character string as a new element into the list 
if other data: the original identifier is simply replaced by [] 
'' ' 
RES = list (var1) # [' fast ',' happy ',' each','A', 'day'] 
RES = List (var3) 
RES = List (var4)
res = list (var5) # [ 'a', 'b', 'c'] dictionary when strong turn, retains the key, discarding the value 
# RES = List (var6) # error 
Print (RES) 
 
 
# tuple tuple turn strong law 
"" " 
If a string: the string of each character as a new element into the tuple 
if other data: that is, simply replace the original identifier () tuples can become 
" " " 
RES = tuple (var1) # ( 'fast', 'happy', 'every', 'a', 'day') 
RES = tuple (var2) 
RES = tuple (var5) # ( 'a', 'B' , 'c') # dictionary when strong turn, retains the key, discarding the value 
Print (RES) 
 
# sET switch set strong law 
"" " 
If a string: the character string as each new element into the collection in 
If other data: the identifier is simply replaced by the original can be set becomes {} 
"" " 
RES = sET (var1) # because disordered, the string is broken 
res = set (var2) # { 1 , 2,3} 
RES = SET (var5) # dictionary when strong turn, retains the key, discarding values,Key, reorder 
Print (RES) 
 
# duplicates filter list 
listvar = [1,2,3,4,5,5,6,7,6] 
Container = SET (listvar) 
Print (Container)
container = list(container)
print(container,type(container))

  

Guess you like

Origin www.cnblogs.com/eliwen/p/10967687.html