Padding a list in python with particular value [duplicate]

self.myList.extend([0] * (4 - len(self.myList)))

This works when padding with integers. Don’t do it with mutable objects.

Another possibility would be:

self.myList = (self.myList + [0] * 4)[:4]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)