if coin == 25 | 10 | 5:
If I replace the ‘|’ with ‘or’ the code runs just fine. I’m not sure why I can’t use ‘|’ in the same statement.
Doing the following doesn’t work either:
if coin == 25 | coin == 10 | coin == 5:
I know bitwise operators can only be used with integers, but other then that is there another difference from logical operators?
a use case – feature flags
Mix and match to plan your day
will i be going home today?
Guess haven’t gone for a hike today…maybe tomorrow
right shift removes bit at flag position. Which, in this case, happens to correspond to the right most bit.
use case – file access permissions
For those looking to check file access permissions there is the stat module
Assumes
~/.bashrc
exists, if not choose a different file you are owner and have read access to.path_f.stat().st_mode & stat.S_IRUSR == stat.S_IRUSR
Looking thru the mundane file (not Linux access control list) permissions. All those flags are crammed into st_mode. In st_mode, on/off bit at 2^8 is that on?
Sources
read user access stat.S_IRUSR
write others access stat.S_IWOTH
os.stat_result
pathlib.Path.stat