Skipar an optional argument among several in Python

Asked

Viewed 21 times

0

In the following code:

 def FuncEx(hashTag, lang="pt-br", pages=3):
        sel.get(f"A hashtag {hashTag}, na linguagem {lang}, no total de {pages} páginas.")

How could I do if I wanted to pass only the parameters hashTag and pages, leaving the lang by default?

I tried something like:

FuncEx("politica", null, 2)

But it didn’t happen.

1 answer

2


Either you call the function with the arguments in order, or you put the name of the arguments when calling. If you want to leave the defaul of lang and send pages, just do:

FuncEx("politica", pages=2)

Ready - as it was not passed neither a second positional argument, nor an argument as name lang, the default value will be used.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.