这篇文章主要讲述如何理解python中的def
一、代码 def _init_(self):
self.home_url='https://ncov.dxy.cn/ncovh5/view/pneumonia'
def get_content_from_url(self,url):
'''
根据URL,获取响应内容的字符串数据
:param url:请求的URL
:return: 响应内容的字符串
'''
#1.发送请求,获取疫情首页
response = requests.get(url)
return response.content.decode()
总结
python中def是用于定义方法函数,可以理解为def就是编写了一个子函数。



