如果您只想格式化该集合中的字符串,可以使用以下内容。也要考虑除
Set
姓名:
mySet = set(['CY110', 'PH100', 'CY100', 'CS100', 'BE110'])
mySet = list(mySet)
sql_create_table = """ CREATE TABLE IF NOT EXISTS marks (id integer PRIMARY KEY,name text NOT NULL,{0} text,{1} text,{2} text,{3} text);""".format(mySet[0],mySet[1],mySet[2],mySet[3])
print(sql_create_table)
如果不转换为列表,则无法直接为集合编制索引以格式化字符串,因为集合的顺序没有如本文所述。
link