1.set() --- list() s = {12,4,3,4}print(list(s)) # [3, 12, 4] lst = [3, 12, 4]print(set(lst)) # {3, 12, 4} tu = (1,2,3,4)print(list(tu)) #[1, 2, 3, 4]print(set(tu)) #{1, 2, 3, 4} s = {1,2,3}print(tuple(s)) #(1, 2, 3) tu = (1,2,3,4)print(str(tu)) lst = [1,2,3,4,[5,6,7,[8,9,10]]]print(str(lst)) print #面向用户的s = str(lst)print(repr(s)) na = ‘alex‘lst = list(na)print(lst) dic = {‘name‘:‘黑哥‘,‘age‘:18}lst = list(dic) # 字典的键print(lst) s = set(dic)print(s) strintboollisttupledictset print(bool(‘ ‘)) Trueprint(bool(‘‘)) False print(bool(0)) Falseprint(bool(56)) True print(bool(True)) Trueprint(bool(False)) False print(bool([1,2,3])) Trueprint(bool([])) # False print(bool((1,2,3))) #Trueprint(bool(())) #False print(bool()) 0 ‘‘ None [ ] ( ) { } { } False print(bool(None)) for i in ‘alex‘: if i: print(44)
原文地址:https://www.cnblogs.com/q240756200/p/9898227.html
时间: 2024-11-26 15:47:40