I read Qiita's article about pythongolf, and I was unable to understand it. In the code below, why is b assigned when a
Applicable source code
What you could see and understand
c = a<b and a or b
And and or can be used for other than Boolean values. And and or can be used even if not in an if statement.
-If the left of or is "true", return the left value.-If the left of or is "false", return the right value.
・ If the left side of "and" is "true", the right value is returned. ・ If the left side of "and" is "false", the left value is returned.
- Compare a and b (False)
- If the left of "and" is "false", the left value is returned, so False is assigned
Answer # 1
2.If the left of and is "false", the left value is returned, so False is assigned
It's a little different.
c = a For
c = (((a
(a Furthermore, if bool (a) is True, c = a, and if False, c = b.If
(a Furthermore, False or b becomes b and c = b.
Be careful when bool (a) is false.
>>>True and 1 or 2 1 >>>True and 0 or 2 2 >>>False and 1 or 2 2 >>>False and 0 or 2 2
- python - about the difference in behavior between sort and sorted
- about the operation of python's speedtest module (library)
- about the behavior of access laccdb files
- python - about pulp shift scheduling
- python - about the problem that the screen display does not work when i have multiple apps in django
- about scraping in python
- about the cause of syntax error: invalid syntax in python
- about wxpython
- about local variable references in python
- about byte processing clipping in python
- python - about session management of flask login
- about the problem that python fails to determine the exact match of a string
- python - about the target method when nothing is returned for the query of table
- python - about processing of for statement
- python - about the place to judge the execution result in the object language
- about python
- about python highpass filter
- python - about dp matching
- python - about operation parameters in machine learning production
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- python 3x - typeerror: 'method' object is not subscriptable
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - unresolved reference comes out in kotlin