传递实参

# 8-3
def make_shirt(size, slogan):
    print("This dress is " + size + ".")
    print("The slogan is " + slogan + "!")

make_shirt('large', 'waste')

# 8-4
def make_shirt(size='large', slogan='I love python'):
    print("This dress is " + size + ".")
    print("The slogan is " + slogan + "!")

make_shirt()
make_shirt('medium')
make_shirt('small', 'I love learning')

# 8-5
def describe_city(city, country='china'):
    print(city.title() + " is in " + country.title() + ".")

describe_city('bei jing')
describe_city(city='he nan')
describe_city('washington', 'america')
This dress is large.
The slogan is waste!
This dress is large.
The slogan is I love python!
This dress is medium.
The slogan is I love python!
This dress is small.
The slogan is I love learning!
Bei Jing is in China.
He Nan is in China.
Washington is in America.
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 鉴于函数定义中可能包含多个形参,因此函数调用中也可能包含多个实参。向函数传递实参的方式很多,可使用位置实参 ,这要...
    python大大阅读 197评论 0 0
  • 预习: 知识点: 8.2 传递实参 位置实参:实参、形参顺序必须相同; 关键字实参:实参由变量名和值组成; 8.2...
    Mr_wang001阅读 158评论 1 0
  • 作业: 鉴于函数定义中可能包含多个形参,因此函数调用中也可能包含多个实参。向函数传递实参的方式很多,可使用...
    陈容喜阅读 154评论 0 0
  • TianAff阅读 143评论 1 2
  • 如果不是儿子拿着地图册惊喜地跑来对我说:"妈妈快看,落基山,我们刚去过的地方,比图册上的美一千倍"。也许我...
    简单生活enjoylily阅读 1,249评论 0 1