我是靠谱客的博主 怕孤单羊,最近开发中收集的这篇文章主要介绍导入函数,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

pizza.py

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

def test_def(size, topping='pepperoni'):
    print("size:"+str(size)+"ntopping:" + topping)

making_pizza.py

# import pizza
# pizza.make_pizza(16, 'pepperoni')
# pizza.make_pizza(20, 'mushrooms','green peppers', 'extra cheese')

# from pizza import make_pizza
# make_pizza(16, 'pepperoni')
# make_pizza(20, 'mushrooms','green peppers', 'extra cheese')

# from pizza import make_pizza as mp
# mp(16, 'pepperoni')
# mp(20, 'mushrooms','green peppers', 'extra cheese')

# import pizza as p
# p.make_pizza(16, 'pepperoni')
# p.make_pizza(20, 'mushrooms','green peppers', 'extra cheese')

from pizza import *
# make_pizza(16, 'pepperoni')
# make_pizza(20, 'mushrooms','green peppers', 'extra cheese')
test_def(12)
test_def(33,"hello")

 

最后

以上就是怕孤单羊为你收集整理的导入函数的全部内容,希望文章能够帮你解决导入函数所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部