Comparing utf decoded value with a string value

I have been trying to compare the UTF-decoded data from pyserial with a value of a similar data type. However, it never returns true.

Please refer to the Python 3 code below:

import serial.tools.list_ports
import serial

serialInst = serial.Serial()

serialInst.bandrate = 9600
serialInst.port = portvar
serialInst.open()


while True:

    if serialInst.in_waiting:

        packet = serialInst.readline()
    
        num = packet.decode("utf")
    
        print("num is: ")
        print(num)       # prints 0
        print(type(num)) # returns <class 'str'>
        
        print(num == '0') # returns false
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum