我正在尝试将javascript代码翻译成python,我遇到的问题是我不知道某些表达式是做什么所以现在我卡住了。这是我想要翻译的代码。
var generateID = function(dob, male, citizen) {
var gender = getRandom(5) + (male ? 5 : 0);//this line if anyone knows what it does
var citBit = +!citizen;//this is the line that i need to translate to a python equivalent
};
答案 0 :(得分:0)
它将转换为布尔值
getRandom = function(s) { return s }
var generateID = function(dob, male, citizen) {
var gender = getRandom(5) + (male ? 5 : 0);//this line if anyone knows what it does
var citBit = +!citizen;//this is the line that i need to translate to a python equivalent
console.log(citBit);
};
generateID(null , 'yes', 1)

答案 1 :(得分:0)
+! will test return opposite boolean representation for your input.
if your input is `true` will return false.
if it is `false` will return `true`
例如:
您的给定输入为> 0
,其布尔表示为1
,因此它将!
并返回false
等效0
。同样,如果其0
将返回1
答案 2 :(得分:0)
如果值为true
,则返回false
;如果值为false
,则返回true