示例#1
0
import pizzas

pizzas.make_pizza(16, 'pepperoni')
pizzas.make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese')

# you can import specific functions from a module

# for example
from pizzas import make_pizza  # imports the function make_pizza from pizzas.py

# you can import and many functions as you want by separating each module with a comma
# for example
# from pizzas import make_pizza, example_function_1, example_function_2

make_pizza(16, "pepperoni")
示例#3
0
import pizzas
pizzas.make_pizza(16, "pepperoni")
pizzas.make_pizza(14, "mushroom", "ham")
# you can also give am alias for a module name
# for example you can give an alias for pizzas as p
# calling p.make_pizza() is more concise than calling pizza.make_pizza()

import pizzas as p

p.make_pizza(16, "pepperoni")
p.make_pizza(12, "ham", "mushroom")

# 
示例#5
0
print('\n')

print_design(unprinted_designs[:], printed_designs)
#This little repeat doesn't do anything, it just demostrates slice notation
#slice notation duplicates a list for the use of a function,
#If a function modifies a list but you want it to remain intact, this is useful

print('\n')


def make_pizza(*toppings):
    print(toppings)


make_pizza('pepperoni')
make_pizza('pepperoni', 'olives', 'mushrooms')
#Notice that so far, arguments have been exact, any devation creating an error
#What if we don't know how many arguments they function will handle?
#Then we can make the function pass an arbitrary amount of arguements
#The '*' infront of the parameter lets it pass diffrent amount of arguements
#Note that these values are packed into a tuple, so no list attributes

print('\n')


def make_pizza(size, *toppings):
    print('Making a ' + str(size) + '-inch pizza with the following toppings:')
    for topping in toppings:
        print('-' + topping)