Cora Coleman Cora Coleman - 8 months ago 33
Python Question

What do the operators "<>" mean in Python?

I'm trying to understand another author's code for writing a Parser in the "NAND to Tetris" project but don't understand what they mean when using the "<>" operators as shown in this chunk of code. I have included their constructor for reference to the self.commands function.

def __init__(self,fname):
self.fname = fname
self.commands = open(fname, 'r').readlines()

def hasMoreCommands(self):
"""Return True if more commands to parse else return False"""
return self.commands <> [ ]

Seems to me like its an easier way of determining if there are more lines in the code. Is that correct? Thank you for any input regarding this question! Please let me know if more info would help.


In Python 2.X, <> is same as != but the usage is obsolete and is discouraged in favour of the newer usage which is !=

Refer the manual for the Comparision section

So, return self.commands <> [ ] is same as return self.commands != [ ] which means the self.commands is not an empty list which as per your docstring

Return True if more commands to parse else return False