<< 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.

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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