Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@apple502j

false vs False 言語対決!

More than 1 year has passed since last update.

備忘録の一種。

True,FalseといったBooleanな値を書くにはということの、言語差を感じた。

JavaScript

return_false.js
function return_false(){
    return false;
}

小文字のfalse、大文字Falseは未定義=変数代入できる、0と1はOK

Python(CPython 3.6)

return_false.py
def return_false():
    return False

こっちは逆で、大文字False、小文字falseは未定義=変数代入できる1

C

return_false.c
/* mainは省略 */
int return_false(void){
    return 0;
}

trueもTrueも通じない。

Ruby(追記 2018/07/07)

Rails開発を始めたので。
ruby:return_false.rb
def return_false
return false
end

小文字のfalseが通じる。FALSEは廃止だがRuby 2.5で使えた。
Falseはだめ。

結論

0と1が無難。

注釈


  1. Pythonの古いバージョンではTrueFalseも変数だった。 

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
apple502j
Logo is by me, CC BY-SA 2.0

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?