[Tutor] Please help me get started on how to program useing python 2.4!!!

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Mar 11 22:07:22 CET 2005



On Fri, 11 Mar 2005 Jeff420harris00 at wmconnect.com wrote:

> OK i have learned that on the python shell if you put, print "some
> message" the output is, some message

Hi Jeff,


Ok, yes, that looks right.  Let me do that myself:

###
>>> print "hello world"
hello world
###

(The '>>>' thing is what the Python shell prints out, as a "prompt" to
tell me that it's ready to read more commands).




> and if you put, type > "some message" the output is, true
>
> and if you put, type< "some message" the output is, false



Hmmmm!  Let me make sure I understand:  are you doing this?

###
>>> type < "some message"
False
>>>
>>>
>>> type > "some message"
True
###

What we are asking Python here is actually a bit weird: we are asking it
to compare the 'type' function to see if it's either "less than" or
"greater than" the string 'some message'.

Did you get these expressions from some online tutorial?  If so, point us
to that tutorial, so I can bonk the author.  *grin*

How are you learning Python?  Are you going through a book, or through
some web page tutorial?


[Note for advanced users: I know that Python will give something that will
return some consistent result.  According to:

    http://www.python.org/doc/ref/comparisons.html

"Most other types compare unequal unless they are the same object; the
choice whether one object is considered smaller or larger than another one
is made arbitrarily but consistently within one execution of a program."

So what Jeff is seeing is a completely arbitrary result, and it's not even
guaranteed to be the same between program executions!  That's why I think
it's the wrong thing to show because it's hard to explain.  And I think
it's a terrible idea to show something like that to a beginner since it's
not something that a sensible programmer would normally do anyway.]



Jeff, I think it might make more sense to compare two things that are the
same kind of thing.  For example, it should make more sense to compare two
numbers to see if one is bigger than the other:

###
>>> 1 > 2
False
>>> 2 > 1
True
###

When we ask: "Is the number 'one' greater than the number 'two'?", Python
is telling us "No!" by giving us back the value 'False'.  Whenever we ask
Python a question that's a yes/no sort of thing, Python will respond with
a value like 'True' or 'False'.


We can also compare strings to see if a word is "bigger" than another
word, based on where it might be located in a dictionary.  For example:

###
>>> "application" < "applied"
True
>>> "applied" < "application"
False
###


In technical terms, we are giving Python expressions that "evaluate" to a
"boolean" value: we're asking Python questions, and it's saying True or
False.  Does this make sense so far?  If not, please continue to ask
questions, and we'll try to show things more clearly.



> And if you put, for, in, or and it turns orange like print dose but I
> don't know why?

If you're using IDLE, then stuff that shows up as orange when it's a
special kind of "keyword".

A keyword is a word that Python knows is a special word.  When you learn
more about Python, you'll see a few more of these keywords.  The orange
coloring is there just to make them stand out from the rest of your
program, and doesn't have any other significance, other than just being
colorful.  *grin*


If you have questions on any of this, please feel free to ask.  Best of
wishes to you!



More information about the Tutor mailing list