lundi 22 février 2021

how to use if statement for function with pre-defined argument

This is my code:

def characters(a=''):
    if a:
        for c in Characters:
            b=c
            print(b)
    else:
        for char in Characters:
            yield char

What I want is, whenever function is called without argument it should print the keys inside dictionary "Characters" and when argument is given it should return the keys instead of printing them. The else statement does it's job but if statement doesn't work.

Aucun commentaire:

Enregistrer un commentaire