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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.