[pythonvis] Python Tip #2 of the day

  • From: "Jeffrey Thompson" <jthomp@xxxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Sat, 17 May 2014 18:50:17 -0400

Python Tip of the Day

 

                As JDog has already stated,

Python is case sensitive.

which means capital letters do not match lower case letters.

This will catch beginning programmers unawares.

 

                One interesting time happened to me:

 

                The keywords "True" and "False" are sometimes useful in
Python code.

 

                if error_flag == True:

                                # handle the error(s) here

 

                Using these two keywords, "True" and "False", does make the
code more readable.

However take note that "true" and "false"

are not keywords!

 

                This is because they are spelled differently.

"true" and "false" do not match because they are all lower case.

Whereas the 2 keywords have their first letter capitalized.

 

So don't forget that the keywords "True" and "False" both have their first
letter capitalized,

and "true" and "false", all in lower case,

are not keywords.

 

If you use the wrong spelling,

Python will object by saying something like

"global "true" is not defined"

 

                One can waste several minutes trying to figure out what is
wrong,

when it sounds perfect as one's screen reader pronounces them both the same.

 

                Jet

Other related posts:

  • » [pythonvis] Python Tip #2 of the day - Jeffrey Thompson