A Python programming tutorial John W. Shipman 2009-11-17 17:17 Abstract A tutorial for the Python programming language. This publication is available in Web form 1 and also as a PDF … A tutorial for the Python programming language. This publication is available in Web form1 and also as a PDF document2. Please forward any comments to tcc-doc@nmt.edu This document contains some tutorials for the Python programming language. These tutorials accompany the free Python classes taught by the New Mexico Tech Computer Center. Another good tutorial is at the Python website3. 1.1. StartingPython in conversational mode This tutorial makes heavy use of Python’s conversational mode. When you start Python in this way, you will see an initial greeting message, followed by the prompt “>>>”. • On a TCC workstation in Windows, from the Start menu, select All Programs ? ActiveState ActivePy- thon 2.5 ? Python Interactive Shell . You will see something like this That second example above may also surprise you. Mathematically, one-fifth is exactly 0.2. However, in Python (as in pretty much all other contemporaryprogramming languages), many real numbers cannot be represented exactly. The representation of 1.0/5.0 has a slight error in the seventeenth decimal place. This behavior may be slightly annoying, but in conversational mode, Python doesn’t know how much precision you want, so you get a ridiculous amount of precision, and this shows up the fact that some values are approximations. You can use Python’s print statement to display values without quite so much precision. Python has a number of built-in functions. To call a function in Python, use this general form: f ( arg 1 , arg 2 , … ) That is, use the function name, followed by an open parenthesis ” (”, followed by zero or more arguments separated by commas, followed by a closing parenthesis “) “. For example, the round function takes one numeric argument, and returns the nearest whole number (as a float number).
Download A Python programming tutorial.
0 comments:
Post a Comment