Y
Y
Yoshinon Eared2017-12-19 14:32:29
Python
Yoshinon Eared, 2017-12-19 14:32:29

Which of the ways to assign values ​​by condition is correct?

Again, controversy about the cleanliness of the code. What code snippet is the most acceptable and why? :)
Option 1

if 'token' in params:
    _token = params['token']
else:
    _token = config.token

Option 2
_token = config.token
if 'token' in params:
    _token = params['token']

Option 3
_token = params['token'] if 'token' in params else config.token

I like the second option the most :)
Thank you for your help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question