*
<>if
* False The ones with high probability are put in front
* The slow ones are put in the back
* else Only with the latest if Make a couple
*
<>if…else… simplified method
*
<> Ternary expression
*
<> be good at using sth. or sb. if return
Academies believe that there is only one function return sentence , because return It's the end .
When there are multiple branches , Proper use return You can end the branch in time .
*
<> The internal contents are extracted into functions
When if…else… When the internal code is complex , It can be extracted into functions , about for It's the same thing .
*
<> notes
*
<> Too many comments are not appropriate
*
<> Function names are clear instead of comments
*
<> The necessity of extraction as function
*
<> The code is complex
*
<> It can be used in other places
*
<> Dyslexia
*
<> View function
*
<> Code needs to be concise
*
<> The origin of business logic
*
<> Read source code
*
<> Layered view , Don't worry about it all
*
<> Ternary expression
*
<> original
if r.status_code == 200: if return_json: return r.json() else: return r.text
else: if return_json: return {} else: return ''
*
<> simplify
def func(): if r.status_code != 200: return {} if return_json else '' return r.
json() if return_json else r.text
Technology
Daily Recommendation