Defining Your Own Modules

Writing and Running a Program, explained that in order to save code for later use, you can put it in a file with a .py extension, and it demonstrated how to run that code. Chapter 3, Designing and Using Functions, also included this function definition:

 >>>​​ ​​def​​ ​​convert_to_celsius(fahrenheit):
 ...​​ ​​""" (number) -> float
 ...
 ... Return the number of Celsius degrees equivalent to fahrenheit degrees.
 ...
 ... >>> convert_to_celsius(75)
 ... 23.88888888888889
 ... """
 ...​​ ​​return​​ ​​(fahrenheit​​ ​​-​​ ​​32.0)​​ ​​*​​ ​​5.0​​ ​​/​​ ​​9.0
 ...

Put the function definition for convert_to_celsius from Defining Our Own Functions, in a file called temperature.py. (You can save this ...

Get Practical Programming, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.