[Tutor] Commands

Alan Gauld alan.gauld at yahoo.co.uk
Thu Jan 23 19:11:19 EST 2020


On 23/01/2020 19:00, Aaliyah Wood wrote:
> I recently started learning Python two days ago using different lessons
> online so my question may sound very uneducated. Python is not recognizing
> any commands (True, False, Print, Int.) 

One thing about programming is that you need to be very precise in your
language. A command in Python is something very specific. None of the
above words are Python commands. Also spelling, punctuation and spacing
are all incredibly important too.

True and False are Python values. They are also "reserved words" meaning
you can't use them for variable names.

Print is just a name(*) to Python. It is very different to print(lower
case) which is a *function* in Python 3 and a *command* in
Python 2 - two very different things!

Int likewise is just a name. int(lower case) however is a built-in type.
It is also a conversion function used to create integers from
(valid)strings(another type) and floats(yet another type).

(*)-------------------
 Names in python are just labels that you can attach to objects. They
usually appear as variables or functions. For example:

foo = 66

creates a name foo and gives it a value of 66

def Print(): pass

creates name a Print and gives it a value of a function which
does nothing(pass). Print won't get a special colour in IDLE but
it will be remembered and offered as an option if you try
typing Pri<tab>. (see below)
------------------------

> I know that these commands turn a
> different color when they're recognized (True and False turn orange)

reserved words turn orange, so True, False, None, if, while, class, def
etc all turn orange - assuming you are using IDLE. The actual colour
will vary depending on the tool you use.

>  How do I fix this?

Mainly by typing the correct word and in the correct place.
But if using IDLE (and some other tools) you do get a little
extra help in that you can type a tab and Python will offer
up a choice of valid options. If you have mistyped there will
be no options(or perhaps a very limited set)

You can select the one you want and IDLE will fill it in
for you - a bit like smart typing on your phone.


Does that help?
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list