Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – creating empty classes and functions


Enter the following code into a text file, or an input cell in a worksheet:

# Create an empty class to use as a data structure
class Struct():
    pass
    
# Use pass to define empty methods
class VTOL():
    """Class to represent airborne vehicles with VTOL
    (Vertical Take-Off/Landing) capabilities, such as
    helicopters, tilt-rotors, and Harrier jump jets.
    """
    def __init__(self):
        pass
    
    def move(self, horizontal_angle, vertical_angle, distance):
        pass
    
data_container = Struct()
    
data_container.name = "String data"
data_container.count = 14
data_container.remainder = 0.1037
    
print(data_container.name)
print(data_container.count)
print(data_container.remainder)

The output should look like this:

sage:  load 4460_9_8.py   
String data
14
0.1037

What just happened?

If you attempt to define a function or a class with no indented code following it, the Python interpreter will give you an error...