Tuesday, December 12, 2017

Boolean and None in Python

As you know about boolean in other programming language. it is same in python too but with small differences .boolean can be  a true or false value.can be declared as either of them.

eg:

python_course = True
java_course = False

Simply type a name and assign a value "True" or False .

if you have noticed only difference with other programming language is that it starts with Capital letter T for True and Capital letter F for False .interestingly you can convert Boolean value to int and it will give you values 1 and 0 in case of True and False like below.

eg:

int(python_course) == 1
int (java_course) == 0
str(python_course) == "True"

And for string it will simply give textual representation "True" or "False".

Now coming to None: it is similar to null like other programming languages.

eg:

aliens_found = None

I find it useful as a place holder variable.Something that I will use later.However there is difference between variable you have defined None and other the  variable not defined at all.
Simply type k in idle and idle will tell you that k has not been defined but if I assign None to k then it will not give any result but normal for None and also it will not cause any error to show either.So None is called None type.

No comments: