DEV Community

pooyaalamdari
pooyaalamdari

Posted on

None data type in python with an example

def get_user(database, user_id):
    # Simulate database lookup
    user = database.get(user_id, None)
    return user

# Simulated database
users = {
    1: 'Alice',
    2: 'Bob',
    # Notice there's no user with ID 3
}

# Fetching a user
user = get_user(users, 3)
if user is None:
    print("No user found with that ID.")
else:
    print(f"User found: {user}")

Enter fullscreen mode Exit fullscreen mode

Top comments (0)