You can use following code for a single value as in your case.
rlayer = iface.activeLayer()
transparency = rlayer.renderer().rasterTransparency()
pixel = QgsRasterTransparency.TransparentSingleValuePixel()
#setting value
pixel.min = 0
#setting transparency level
pixel.percentTransparent = 100
transparency.setTransparentSingleValuePixelList( [pixel] )
layer.triggerRepaint()
However, for an interval of values it is preferable to use following code instead.
rlayer = iface.activeLayer()
transparency = rlayer.renderer().rasterTransparency()
n = 2
pixels = [ QgsRasterTransparency.TransparentSingleValuePixel()
for i in range(n) ]
min = [ min1, min2 ] # change min1, min2 for a numeric value
max = [ max1, max2 ] # change max1, max2 for a numeric value
trpcy = 100
for i, item in enumerate(pixels):
item.min = min[i]
item.max = max[i]
item.percentTransparent = trpcy
transparency.setTransparentSingleValuePixelList( pixels )
layer.triggerRepaint()