コード例 #1
0
ファイル: pooch.py プロジェクト: jandrews2014/Projects
#Start a new Python module by defining a function that
#supplies a default string value to its argument
def bark(pet='A Dog'):
    print(pet, 'Says WOOF!')


#Next, add two more function definitions that also supply
#default string values to their arguments
def lick(pet='A Dog'):
    print(pet, 'Drink water')


def nap(pet='A Dog'):
    print(pet, 'Sleeps In The Sun')


#Start a new Python script with a statement to make
#individual "dog" module functions available
from dog import bark, lick, nap

#Next, call each function without supplying an argument
bark()
lick()
nap()

#Now, call each function again and pass an argument value
#to each then save the file
bark('Pooch')
lick('Pooch')
nap('Pooch')
コード例 #2
0
#instead of importing the entire program we can import only the neccessary 
#functions using the from import(command)

from dog import bark,lick,nap

bark()
lick()
nap()

#try it with entering a parameter

bark("Pooch")
lick("Pooch")
nap("Pooch")

コード例 #3
0
from dog import bark, lick, nap

bark()
lick()
nap()
コード例 #4
0
ファイル: fido.py プロジェクト: jandrews2014/Projects
#default string values to their arguments
def lick(pet='A Dog'):
    print(pet, 'Drink water')


def nap(pet='A Dog'):
    print(pet, 'Sleeps In The Sun')


#Start a new Python script with a statement to make
#individual "dog" module functions available
from dog import bark, lick, nap

#Next, call each function without supplying an argument
bark()
lick()
nap()

#Now, call each function again and pass an argument value
#to each then save the file
bark('Pooch')
lick('Pooch')
nap('Pooch')

#Start another Python script by making all "dog" module
#functions available
from dog import *

#Then, request the user enters a name to overwrite the
#default argument value
pet = input('Enter A Pet Name:')