Python IDLE

You can run commands directly into the IDLE shell.  From the command prompt type IDLE and hit enter.  This should launch the IDLE Python Interpreter.  Do this now.

IDLE

A window like the one above should appear.

Now let’s explore the IDLE and Python commands at the same time.  Type the following into the IDLE then hit return.

>>>3 + 2
output: 5

>>>10-2
output: 8

>>>2*2
output: 4

>>>4/2
output: 2.0   #dividing 2 integers returns a float (float i a number with a decimal point)

>>>4 / 2 + 10
output:  12

>>>4 / (2 + 10)
output:  .3333333  #because Python performs tasks in the parenthesis first

>>>2**3  #exponents 2 x 2 x 2
output:  8

>>>2**4  # to the 4th power 2 x 2 x 2 x 2
output:  16

>>>14 // 3
output:  4  #this is the whole number from division

>>>14%3
output:  2  #this caluclates the remainder, good for finding even numbers

>>>abs(-4)
output:  4  #absolute value

>>>min(1,2,3,4,5)
output:  1  #finds the minimum value in the set

>>>max(1,2,3,4,5)
output:  5 #finds the maximum value in a set

 

Now try these boolean expressions (boolean is either True or False)

>>> 2 < 3
output: True

>>>3 < 3
output: False

>>>4 – 1 >= 2 + 1
output:  True

>>>5 != 6
output:  True  # != means not equal to

 

Let’s try some strings.  Notice how IDLE remembers what is typed on the lines above.  You can type a program line by line if you choose.

>>>print(“Hi Ho “)
output:  Hi Ho

>>>print(“Hi ho ” * 5)
output:  Hi ho Hi ho Hi ho Hi ho Hi ho

>>>myName = “Fergie”

>>>print(“myName”)
output:  myName  #just printed what was in the quotes

>>>print(myName)
output:  Fergie  #recalled the variable value

>>>place = “Cafe”

>>>print(place + myName)
output: CafeFergie

>>>print(place + ” ” + myName)
output:  Cafe Fergie

 

Notes:

Minus and division do not work with strings since there is no common sense way to apply them to strings.

<– PREVIOUS  or  NEXT –>