Книга: Fedora™ Unleashed, 2008 edition

Getting Interactive

Getting Interactive

We will be using the interactive interpreter for this chapter, so it is essential that you are comfortable using it. To get started, open a terminal and run the command python. You should see this:

[paul@caitlin ~]$ python
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> is where you type your input, and you can set and get a variable like this:

>>> python = 'great' >>> python
'great'
>>>

On line 1, the variable python is set to the text great, and on line 2 that value is read back from the variable when you type the name of the variable you want to read. Line 3 shows Python printing the variable; on line 4, you are back at the prompt to type more commands. Python remembers all the variables you use while in the interactive interpreter, which means you can set a variable to be the value of another variable.

When you are finished, press Ctrl+D to exit. At this point, all your variables and commands are forgotten by the interpreter, which is why complex Python programs are always saved in scripts!

Оглавление книги

Оглавление статьи/книги

Генерация: 0.959. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз