泛舟湖上清波郎朗
一种方法是在字符串之间来回转换:# convert float to a stringnum = 3.142strnum = str(num)# order the string lexicographically, using built-in method sortedordered = sorted(strnum)# ordered = ['.', '1', '2', '3', '4']# get the middle three elements at indices 1, 2, and 3, using a list slicemiddle = ordered[1:4]# middle = ['1', '2', '3']# convert them into integers if desired, using a list comprehensionmiddle_ints = [int(e) for e in middle]# middle_ints = [1, 2, 3]