码迷,mamicode.com
首页 > 其他好文 > 详细

函数:动手试一试

时间:2017-12-31 00:38:23      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:python   lov   pos   col   编写   hang   this   int   body   

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)

 

函数:动手试一试

标签:python   lov   pos   col   编写   hang   this   int   body   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!