How can one form if А , B , C are sets ( set() )?

The compiler swears at this:

 def check(): if label_1["text"] == "": label_1["text"] = "1) %d - %d = %d" % (self.A, self.B, self.A - self.B) label_1.grid() elif label_2["text"] == "": label_2["text"] = "2) %d & %d = %d" % (self.B, self.A, self.B & self.A) label_2.grid() elif label_3["text"] == "": label_3["text"] = "3) (%d - %d) | (%d & %d) = %d" % (self.A, self.B, self.B, self.A, (self.A - self.B) | (self.B & self.A)) label_3.grid() elif label_4["text"] == "": label_4["text"] = "4) ((%d - %d) | (%d & %d) ) \ (%d | %d) = %d" % \ (self.A, self.B, self.B, self.A, self.C, self.B, ((self.A - self.B) | (self.B & self.A)) - (self.C | self.B)) label_4.grid() elif label_5["text"] == "": label_5["text"] = "Result: %s" % str(((self.A - self.B) | (self.B & self.A)) - (self.C | self.B)) label_5.grid() 
  • What traysbek? Add the error code to the question - dedifferentiator
  • Do I have to format? - dedifferentiator 2:42 pm
  • already figured out, thanks - Artem Aleksandrovich
  • one
    Replace %d (formatting the argument as an integer) with %s (formatting as a string). In general, it is not very clear why you moved from a more flexible format and curly brackets to formatting through % . - insolor

1 answer 1

Starting with Python 3.6, you can use Formatted string literals AKA f-string :

 In [30]: A = set([1,2,3]) In [31]: B = set([2,3,4]) In [32]: f'{A} - {B} = {AB}' Out[32]: '{1, 2, 3} - {2, 3, 4} = {1}' 

alternative:

 In [35]: '{} - {} = {}'.format(A, B, AB) Out[35]: '{1, 2, 3} - {2, 3, 4} = {1}'