Previous: [Chapter 12](Chapter 12.ipynb) [Learning Computing with Robots](Learning Computing with Robots.ipynb) Next: [Myro Overview](Myro Overview.ipynb)

# Python Overview¶

### Chapter 1¶

calico or calico.bat

This is the file you double-click on to start a Calico Session.

icalico or icalico.bat

This is the file you double-click on to start a iCalico iPython Session. Notebooks are another way to mix software with prose, pictures, and links.

Note: All commands you type (including the Myro commands listed above) are essentially Python commands. Later, in this section we will list those commands that are a part of the Python language.

### Chapter 2¶

def <FUNCTION NAME>(<PARAMETERS>):
<SOMETHING>
...
<SOMETHING ELSE>



Defines a new function named <FUNCTION NAME>. A function name should always begin with a letter and can be followed by any sequence of letters, numbers, or underscores (_), and not contain any spaces. Try to choose names that appropriately describe the function being defined.

### Chapter 3¶

Values

Values in Python can be numbers (integers or floating point numbers) or strings. Each type of value can be used in an expression by itself or using a combination of operations defined for that type (for example, +, -, *, /, % for numbers). Strings are considered sequences of characters (or letters).

Names

A name in Python must begin with either an alphabetic letter (a-z or A-Z) or the underscore (i.e. _) and can be followed by any sequence of letters, digits, or underscore letters.

ask(<prompt string>) or input(<prompt string>)

This function prints out <prompt string> in the IDLE window and waits for the user to enter an answer. The result is returned as a string.

float(ask(<prompt string>)

Convert the user's response to a floating point number.

from myro import *
initialize("comX")

<any other imports>
<function definitions>
def main():
<do something>
<do something else>
...
main()



This is the basic structure of a robot control program in Python. Without the first two lines, it is the basic structure of all Python programs.

print (<expression1>, <expression2>, ...)

Prints out the result of all the expressions on the screen (in the IDLE window). Zero or more expressions can be specified. When no expression is specified, it prints out an empty line.

<variable name> = <expression>

This is how Python assigns values to variables. The value generated by <expression> will become the new value of <variable name>.

range(10) Generates a sequence, a list, of numbers from $0..9$. There are other, more general, versions of this function. These are shown below.

range(n1, n2)

Generates a list of numbers starting from $n1...(n2-1)$. For example,

range(5, 10) will generate the list of numbers [5, 6, 7, 8, 9]. range(n1, n2, step)

### Chapter 8¶

In this chapter we presented informal scope rules for names in Python programs. While these can get fairly complicated, for our purposes you need to know the distinction between a local name that is local within the scope of a function versus a global name defined outside of the function. The text ordering defines what is accessible.

### Chapter 9 & 10¶

There were no new Python features introduced in this chapter.

### Chapter 11¶

The only new Python feature introduced in this chapter was the creation of modules. Every program you create can be used as a library module from which you can import useful facilities.

 Previous: [Chapter 12](Chapter 12.ipynb) [Learning Computing with Robots](Learning Computing with Robots.ipynb) Next: [Myro Overview](Myro Overview.ipynb)