Datasheet

After you’ve started the shell, you’ll be presented with some information that you don’t have to be con-
cerned about now (from, import, pcapp, and so on), followed by the sign that the interpreter is ready
and waiting for you to work with it:
>>>.
>>> import wx
>>> from PythonCard import dialog, util
>>> bg = pcapp.getCurrentBackground()
>>> self = bg
>>> comp = bg.components
>>>
How It Works
The codeEditor is a program written in Python, and the Python shell within it is actually a special pro-
gramming environment that is enhanced with features that you will use later in the book to help you
explore Python. The
import, from, and other statements are covered in Chapter 7 in depth, but for now
they’re not important.
Beginning to Use Python — Strings
At this point, you should feel free to experiment with using the shell’s basic behavior. Type some text, in
quotes; for starters, you could type the following:
>>> “This text really won’t do anything”
“This text really won’t do anything”
>>>
You should notice one thing immediately: After you entered a quote (“), codeEditor’s Python shell changed
the color of everything up to the quote that completed the sentence. Of course, the preceding text is abso-
lutely true. It did nothing: It didn’t change your Python environment; it was merely evaluated by the run-
ning Python instance, in case it did determine that in fact you’d told it to do something. In this case, you’ve
asked it only to read the text you wrote, but doing this doesn’t constitute a change to the environment.
However, you can see that Python indicated that it saw what you entered. It showed you the text you
entered, and it displayed it in the manner it will always display a string—in quotes. As you learn about
other data types, you’ll find that Python has a way of displaying each one differently.
What Is a String?
The string is the first data type that you’re being introduced to within Python. Computers in general,
and programming languages specifically, segregate everything they deal with into types. Types are cate-
gories for things within a program with which the program will work. After a thing has a type, the pro-
gram (and the programmer) knows what to do with that thing. This is a fundamental aspect of how
computers work, because without a named type for the abstract ideas that they work with, the computer
won’t know how to do basic things like combine two different values. However, if you have two things,
and they’re of the same type, you can define easy rules for combining them. Therefore, when the type of
a thing has been confirmed, Python knows what its options are, and you as the programmer know more
about what to do with it.
5
Programming Basics and Strings
04_596543 ch01.qxd 6/29/05 10:59 PM Page 5