Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How I can check if the list in Python is empty

I have a list of users on the list and want to print for them some greetings but if I have in this list I should print some another text Hello Admin, would you like to see a status report?. Also I want to have some notification if the list is empty but I don’t know how to do this.

users_site = []
for site in users_site:
    if site == 'Admin':
        print ("Hello Admin, would you like to see a status report?")
    if site == []:
        print ("We need more user's")
    else:
        print (f"Hello, {site}")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Does this help?

users_site = ['']

if not users_site:
    print ("We need more user's")
 
else:
    
    for site in users_site:
        if site == 'Admin':
            print ("Hello Admin, would you like to see a status report?")
            
        else:
            print (f"Hello, {site}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading