Function Phraseology

Python (and java and C++) is a Foreign Language.

You have already learned in another handout that Python uses variables in place of both pronouns and nouns.

English Parts of Speech

You will now have to learn about verbs and sentences.

All of the commands in Python are Imperative – that means they are commands, not statements of fact, and not questions.

Remember that a sentence has a subject and a predicate.

Joe eats pizzas.

The subject was “Joe” and the predicate was “eats pizzas”

Predicates have a verb in them. Above the verb was “eats”.

When a Python statement looks like a statement, it really means “Make it so”.

Joe eats steak.

=> Make it so that Joe eats steak.

Predicates may have other stuff in them such as adverbs, prepositional phrases, and objects.

Mary often keeps her book inside a desk.

The subject was “Mary”

The predicate was “often keeps her book inside a desk”

The verb was “keeps”

An adverb was “often”

A propositional phrase was “inside a desk”

The object was “her book”

Python Sentences

Python has a completely different way of writing sentences. Basically it is like this:

subject . verb ( predicate_stuff )

So the subject appears first, then there is a dot, then the verb, then an open parenthesis (, then possibly other predicate stuff, and finally a close parenthesis). There is NEVER a period at the end of the sentence.

So the English:

Sam drives a Chevy.

Becomes the Python:

sam . drives ( aChevy )

And remember that this really means:

Make it so that sam drives a chevy.

Python Articles and Adjectives

Python does not have articles like “a” and “the” and does not have adjectives so just stick them as prefixes on the variable name to get the idea across.

Thus the English

a big red ball

in Python just becomes a single variable name:

aBigRedBall

where the capitals are used to indicate the word breaks inside the variable name. Some programmers use an underscore _ for the same purpose. The underscore _ is considered to be an honorary letter. The above example could also be:

a_big_red_ball

and actually the programmer could just use the variable

x

instead of aBigRedBallas long has the programmer remembers that x should refer to a big red ball. The use of the longer variable name is considered GOOD PRACTICE since it makes the program easier to understand.

Verb Subsumption

Often in Python, the adverbs and prepositional phrases and even objects are subsumed into the verb (i.e. attached as suffixes) . Hence the English

In summertime, Mary often likes melons.

Could become any of these Python statements:

mary . likes ( summertime, often, melons )

mary . oftenLikes (summertime, melons)

mary . oftenLikesInSummertime ( melons )

mary . oftenLikesMelons ( summertime )

etc. etc.

So which translations are correct? It depends on the module you have imported or the classes and methods you have defined. And it depends on what class of thing mary refers to.

None of the words: mary, often, likes, summertime, or melons has any standard meaning built into the Python language. As far as Python is concerned they are all just pronouns. The programmer is one who must see to it that they each have a reference.

Building meanings for ordinary real world stuff into your program is a difficult task. – one you will delay until later.

Python to English Practice

You should practice translating Python into English. Here are some Python commands and their English translations:

1.mary . dates ( bill )

Mary dates Bill.

2.sue .eatsSquash(often)

Sue often eats squash.

3.aBall .bouncedInto ( thePool )

A ball bounced into the pool.

4.alice . boughtFrom(aCostlyNecklace , sachs)

Alice bought a costly necklace from Sachs.

5.theGolfBall . hitOnHis ( joe , head )

The golf ball hit Joe on his head.

Prepositional Phrases

Python (but not yet for Java) has a special way to deal with prepositional phrases like:

at the corner bank

A prepositional phrase has a preposition and an object. In the above example the preposition is “at” and the object of the preposition is “the corner bank”.

Python would translate an English sentence like:

Joe deposited his savings at the corner bank.

Into:

joe . deposited ( hisSavings , at = theCornerBank )

Thus the general Pythonic form of a prepositional phrase is:

preposition = object_of_preposition

And it goes into the ( ) after the verb just like any other object.

Python calls this prepositional phrase a keyword parameter. It calls the preposition a keyword and it calls the object a keyword value.

Keyword Practice

6.theGolfBall . hit ( joe , on=hisHead )

The golf ball hit Joe on his head.

7.aDog . wasGiven ( aBone , by=billySmith , in=thePark )

A dog was given a bone by Billy Smith in the park.

8.aDeposit.wasMade(by=aGirl, on=Friday,

inAmountFranks=300 )

A deposit was made by a girl on Friday in the amount of 300 franks.

Notice how words in a prepositional phrase can be subsumed into the preposition itself.