首页 > 其他 > 详细

函数:动手试一试

时间:2017-12-31 00:20:49      阅读:220      评论:0      收藏:0      [点我收藏+]

1.编写一个函数,打印一个句子,调用这个含函数

def test():
    print(‘Hello World‘)
test()

2.设置函数和形参,打印消息,调用函数,输入实参

def python(job):
    print(‘Python 适合就业的方向我比较喜欢‘+job)
python(‘机器学习(Scikit-Learn)、神经网络(TensorFlow)和爬虫(Scrapy )‘)

3.编写一个函数,接收尺码和字样,打印

def shirt(size,word):
    print(‘This shirt is:‘+size+‘\nThe word is ‘+word)
shirt(‘L‘,‘Hello World‘)

4.默认参数为‘I love python’的大号,打印一个默认的,在打印一个其他字样尺码无所谓的

def shirt(size=‘大号‘,word=‘I love python.‘):
    print(‘This shirt is:‘+size+‘\nThe word is ‘+word)
shirt()
shirt(word=‘I am learning python‘)

5.编写一个函数,它接受一个城市的名字和该城市隶属的国家。打印一个简单的句子,存储国家的形参为默认值。为三座不同的城市调用这个函数,其中一个不属于这个国家

def city(name,country=‘China‘):
    print(name.title()+‘ is in ‘+country+‘.‘)

city(‘Beijing‘)
city(‘shanghai‘)
city(name=‘Los Angeles‘,country=‘USA‘)

 

函数:动手试一试

原文:https://www.cnblogs.com/xusuns/p/8151507.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!