Empty dictionaries evaluate to False in Python:

>>> dct = {}
>>> bool(dct)
False
>>> not dct
True
>>>

Thus, your isEmpty function is unnecessary. All you need to do is:

def onMessage(self, socket, message):
    if not self.users:
        socket.send("Nobody is online, please use REGISTER command" \
                    " in order to register into the server")
    else:
        socket.send("ONLINE " + ' ' .join(self.users.keys()))
Answer from user2555451 on Stack Overflow
๐ŸŒ
Medium
pavolkutaj.medium.com โ€บ how-to-check-if-a-list-dict-or-set-is-empty-in-python-as-per-pep8-35d8c64d07d0
How to Check if a List, Dict or Set is Empty in Python as per PEP8 | by Pavol Z. Kutaj | Medium
September 7, 2023 - duck typing means relying on general/conventional interfaces โ†’ rather than explicitly checking for types โ†’ you could argue that conventional interfaces are not magical, right ยท so something like if a == [] is forcing a particular type (() ...
๐ŸŒ
DEV Community
dev.to โ€บ awesome_aj1298 โ€บ different-ways-to-check-if-object-is-empty-or-not-146
Different ways to check If Object is empty or not - DEV Community
September 18, 2020 - Checking if the Object is empty or not is quite a simple & common task but there are many ways to...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ check-if-python-json-object-is-empty
Check If Python Json Object is Empty - GeeksforGeeks
July 23, 2025 - In this article, we explored three different methods to check if a JSON object is empty in Python.
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ python
Python IsEmpty Function: A Detailed Guide
July 4, 2023 - When it comes to checking if a string is empty in Python, we can use similar methods as we did with sequences and collections. Just like with sequences and collections, the len() function can be used to check if a string is empty.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-check-if-a-value-is-none-or-empty-in-python-559594
How to Check If a Value Is None or Empty in Python | LabEx
Learn how to check for None and empty values in Python. Discover the difference between None and empty strings/lists using the `is` operator and boolean context. Python None check, Python empty value check.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-check-if-variable-is-empty-in-python
How To Check If Variable Is Empty In Python? - GeeksforGeeks
July 23, 2025 - In this example, the code checks if the string variable `my_list` is empty by evaluating its truthiness.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-check-if-dictionary-is-empty
Check if dictionary is empty in Python - GeeksforGeeks
October 6, 2024 - It's common to need to check whether a set is empty in various programming scenariosPython# Initializing an empty set s = set() print(bool(s)) # False since the set is empty print(not bool(s)) # True since the set is empty
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ check if variable is empty in python
Check if Variable is Empty in Python [5 Ways] - Java2Blog
November 23, 2023 - Therefore, a simple boolean check with not operator can determine if a variable is empty. ... The not operator is a logical operator in Python that returns True if the expression to its right evaluates to False, and False if the expression evaluates ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-check-if-a-list-is-empty-in-python
Python isEmpty() equivalent โ€“ How to Check if a List is Empty in Python
April 19, 2023 - In the code above, we used an if statement and the not operator to check if the people_list was empty. You can use the len() function in Python to return the number of elements in a data structure.
๐ŸŒ
PyTutorial
pytutorial.com โ€บ check-if-variable-is-empty-in-python
PyTutorial | How to Properly Check if a Variable is Empty in Python
February 29, 2020 - #empty variable var = "" #check if variable is empty if len(var) == 0: print("yes it is!")
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-check-if-nonetype-or-empty
Python Check if Nonetype or Empty - GeeksforGeeks
July 23, 2025 - In this example, the below Python code defines a list named `my_list` containing elements of different types (None, an empty string, and an integer). It then iterates through each element in the list using a for loop. For each element, it checks its type and prints a corresponding message. ... my_list = [None, '', 42] for item in my_list: if item is None: print(f"{item} is of NoneType") elif item == '': print(f"{item} is an empty string") else: print(f"{item} is neither None nor an empty string")
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-check-if-a-list-is-empty-in-python
How to check if a list is empty in Python?
If the list is empty, then it returns True; otherwise, False, which means the list is not empty. The following program checks whether the input list is empty or not using the not operator - # empty list lst = [1,2,3,4,5] # evaluating empty list object to False if not lst: print('Empty list') else: print('List is not Empty \n',lst)
๐ŸŒ
Codecademy Forums
discuss.codecademy.com โ€บ frequently asked questions โ€บ python faq
How can I determine if a dictionary is empty? - Python FAQ - Codecademy Forums
June 28, 2018 - Answer Yes, there are several ways to check if a dictionary is empty. The more standard Python method is to use a Boolean evaluation on the dictionary. An empty dictionary (or other containers) will evaluate to a Boolean False.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ check if a string is empty in python
Check if a string is empty in Python | Sentry
if my_string.strip() == "": print("my_string is an empty string!") else: print("my_string is not an empty string!") Sentry BlogPython Performance Testing: A Comprehensive Guide (opens in a new tab) Syntax.fmListen to the Syntax Podcast (opens in a new tab) Sentry BlogLogging in Python: A Developerโ€™s Guide (opens in a new tab)