Idioms and Style

Idioms

What's an idiom?

Some French and Spanish Idioms

BTW, does anyone know the literal and idiomatic translations for these sayings?

Idioms in Programming Languages

An idiom in a programming language is:

More About Programming Language Idioms

Let's See an Example of an Idiom

#  one way to do it; check each value
if name == 'Kermit' or name == 'Gonzo' or name == 'Skeeter':
    print(name + ' is a muppet!')
#  the idiomatic way; check for membership in a list
muppets = ['Kermit', 'Gonzo', 'Skeeter']
if name in muppets:
    print(name + ' is a muppet!')

(we'll look at lists later in the semester)

About Style

PEP 8

In Python, an enhancement proposal, called PEP 8, lays out some good rules to follow.

Here Are a Few Conventions To Follow

if answer == 5:
    print('correct')!
x = 2
y = 5

print("x plus y is ...")
print(x + y)

And a Few More…

#  do this:
count = count + 1
#  *not* this:
count=count+1
#  do this:
count = 0
#  *not* this:
Count=0
#  do this:
my_count = 1
#  *not* this:
mycount = 1
myCount = 1

Make sure your code is formatted in a way that is readable and is consistent with common conventions.