Python3
arr = ['Apple', 'Gorilla', 'Rappa']
print(arr[False])
#Apple
print(arr[True])
#Gorilla
It feels too bad
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.
Python3
if True >= False:
print('True')
else:
print('False')
# True
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
** 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