在使用print格式化输出时,可以通过元组和集合的操作来实现更灵活的输出效果。以下是一些元组和集合操作技巧:
t = (1, 2, 3)
print("Tuple elements are: {}, {}, {}".format(*t))
s1 = {1, 2, 3}
s2 = {2, 3, 4}
print("Elements in set1 but not in set2 are: {}".format(s1 - s2))
s1 = {1, 2, 3}
s2 = {2, 3, 4}
print("Common elements in set1 and set2 are: {}".format(s1 & s2))
s1 = {1, 2, 3}
s2 = {2, 3, 4}
print("All elements in set1 and set2 are: {}".format(s1 | s2))
这些操作技巧可以帮助我们更好地控制输出格式,使输出结果更加灵活和易读。