if True> = False: Python "True" Go "What ???"

\huge{True >= False} What this…… TL;DR

Python3


arr = ['Apple', 'Gorilla', 'Rappa']
print(arr[False])
#Apple
print(arr[True])
#Gorilla

It feels too bad

Introduction

I'm Nia Hoshino, a virtual engineer. This article is the 17th day (impression of the article) of Hoshino Near Advent Calendar 2020. To be correct, it is a solution to the question in program processing for the sentence True> = False that appears in the article.

Python conditional branching is True

Python3


if True >= False:
    print('True')
else:
    print('False')
# True

why

Python's Bool type is implemented as a subclass of integers Treats 1> = 0 and returns True. Boolean Object — Python 3 \ .9 \ .1 Document If you divide by False, Zero Division Error will be returned.

print(str(True + False));
# 1
print(str(True + True));
# 2
print(str(False + False));
# 0
print(True / False)
# ZeroDivisionError: division by zero

For other languages

** Typed loose fluffy language first Javascript: true ** Javascript division by zero results in Infinity

Javascript


console.log(true >= false);
// true
console.log(true);
// true
console.log(true + true);
// 2
console.log(true + false);
// 1
console.log(true / false);
// Infinity

** Statically typed Golang: operator> = not defined on bool ** Really correct behavior

Go


package main
import "fmt"
func main(){
    if true >= false{
        fmt.Println("true")    
    }else{
        fmt.Println("false")
    }
    // invalid operation: true >= false (operator >= not defined on bool)
}

Recommended Posts

if True> = False: Python "True" Go "What ???"
[Python] if __name__ == What is'__main__' :?
Python if statement
Python with Go
What is python
[Python] if statement
What is Python
What I do when imitating embedded go in python
[Python] What is Pipeline ...
[Python] What is virtualenv
Python basic if statement
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
Python "if __name__ == ‘__main__’: ”means
Addition with Python if statement
[Python] Python and security-① What is Python?
[Python] * args ** What is kwrgs?
What I learned in Python
What is a python map?
Python Basic Course (1 What is Python)
What to do if Python doesn't work on Git for Windows
What to do if you can't install pyaudio with pip #Python
What to do if python says "fatal error:'stdio.h' file not found"
python> API> nargs ='?' <Parser.add_argument ('--fake_data', nargs ='?', Const = True, type = bool, default = False,
What to do if Insecure Platform Warning appears when running Python
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows