<< Chapter < Page Chapter >> Page >

Command line versus GUI

The text in Figure 4 was produced using the Python (command line) interface. I don't get exactly the same behavior (with respect to prompts) when I use the Python GUI interface. Rather, what I get is shown in Figure 3 . (Note the missing ... prompt.)

The difference between the ... prompt and the>>>prompt is discussed in section 2.1.2. Interactive Mode of The Python Tutorial . (Note that the tutorial is also accessible in a different format from the Start/All Programs/Python 3.4 selection in Windows.)

Apparently the command-line interface creates the ... prompt when it thinks that the next line is a continuation line. The example given in the tutorial isshown in Figure 5 . (Don't be concerned if you don't understand the code in Figure 5 . I will explain similar code in a future module.)

Figure 5 . Example prompts from The Python Tutorial.
>>>the_world_is_flat = True>>>if the_world_is_flat: ... print("Be careful not to fall off!")... Be careful not to fall off!

Apparently for the case of Figure 4 , the system became confused by the comment and treated the line after the comment as a continuation line.

The IDLE GUI did not become confused in Figure 3 . I believe that it accomplishes line continuation by automatically indenting the next line and nocontinuation was required in either Figure 3 or Figure 4 .

Let's get technical

But not too technical. Computer programs are made up of statements.

Statements are composed of expressions.

(Later we will learn that large Python programs are made up of smaller programs called modules, which are made up of statements, which are composed ofexpressions.)

Statement ends at the end of the line

In Python, a statement normally ends at the end of the line that contains it (although there are exceptions to this rule) .

For the time being, suffice it to say that expressions are made up of

  • literal values
  • variables
  • operators
  • parentheses

Literal values and variables

Literal values are simply numbers that are included in an expression such as the 2 and the 5 shown in Figure 3 .

I will defer a discussion of variables until a future module, and will discuss operators and parentheses in the following paragraphs.

Operators

If you have ever used a hand calculator, you already know what operators are. The plus key on a hand calculator is an operator. The plus sign (+) in the expression shown in Figure 6 is also an operator.

Figure 6 . A Python addition operator.
>>>2+5

In programming jargon, operators are said to operate on operands ..

Operands

In Figure 6 , the 2 is the left operand and the 5 is the right operand of the + operator.

Unary and binary operators

Normally, operators are said to be either unary or binary .

A unary operator has only one operand while a binary operator has two operands.

Some can be either

Some operators, such as the minus sign (-), can be either unary or binary operators.

In its unary mode with a single operand, a minus sign is usually a sign changing operator, while in its binary mode with two operands, a minus sign is usually a subtraction operator.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Itse 1359 introduction to scripting languages: python. OpenStax CNX. Jan 22, 2016 Download for free at https://legacy.cnx.org/content/col11713/1.32
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?

Ask