Given that assert can be optimized when you run the interpreter with -O , you probably want to store it in a single statement and use string concatenation in brackets:
assert 0 <= j <= self.n, ('First edge needs to be between ' '0 and {}'.format(self.n))
or using f-lines in Python 3.6+:
assert 0 <= j <= self.n, ('First edge needs to be between ' f'0 and {self.n}')
If you are not interested in optimization (for example, you write tests), then the option of splitting into two operators is also possible:
message = 'First edge needs to be between 0 and {}'.format(self.n) assert 0 <= j <= self.n, message
source share