当前位置: 首页 > news >正文

花都b2b网站建设公司seo到底是做什么的

花都b2b网站建设公司,seo到底是做什么的,网站福利你们会回来感谢我的,wordpress标签云美化大家好,今天给大家分享一下明哥整理的一篇 Python 参数的内容,内容非常的干,全文通过案例的形式来理解知识点,自认为比网上 80% 的文章讲的都要明白,如果你是入门不久的 python 新手,相信本篇文章应该对你会…

大家好,今天给大家分享一下明哥整理的一篇 Python 参数的内容,内容非常的干,全文通过案例的形式来理解知识点,自认为比网上 80% 的文章讲的都要明白,如果你是入门不久的 python 新手,相信本篇文章应该对你会有不小的帮助。

接下来是正文。

文章目录

    • 技术交流
    • 1. 参数分类
    • 2. 十一个案例
    • 3. 传参的坑

技术交流

技术要学会分享、交流,不建议闭门造车。一个人走的很快、一堆人可以走的更远。

本文来自技术群粉丝分享整理,资料资料、数据、技术交流,均可加交流群获取,群友已超过2000人,添加时最好的备注方式为:来源+兴趣方向,方便找到志同道合的朋友。

方式①、添加微信号:pythoner666,备注:来自CSDN +备注来意
方式②、微信搜索公众号:Python学习与数据挖掘,后台回复:加群

1. 参数分类

函数,在定义的时候,可以有参数的,也可以没有参数。

从函数定义的角度来看,参数可以分为两种:

  1. 必选参数:调用函数时必须要指定的参数,在定义时没有等号

  2. 可选参数:也叫默认参数,调用函数时可以指定也可以不指定,不指定就默认的参数值来。

例如下面的代码中,a 和 b 属于必选参数, c 和 d 属于可选参数

def func(a,b,c=0, d=1):  pass  

从函数调用的角度来看,参数可以分为两种:

  1. 关键字参数:调用时,使用 key=value 形式传参的,这样传递参数就可以不按定义顺序来。

  2. 位置参数:调用时,不使用关键字参数的 key-value 形式传参,这样传参要注意按照函数定义时参数的顺序来。

def func(a,b,c=0, d=1):  pass  # 关键字参数传参方法  
func(a=10, c=30, b=20, d=40)  # 位置参数传参方法  
func(10, 20, 30, 40)  

最后还有一种非常特殊的参数,叫做可变参数

意思是参数个数可变,可以是 0 个或者任意个,但是传参时不能指定参数名,通常使用 *args**kw 来表示:

  • *args:接收到的所有按照位置参数方式传递进来的参数,是一个元组类型

  • **kw :接收到的所有按照关键字参数方式传递进来的参数,是一个字典类型

def func(*args, **kw):  print(args)  print(kw)  func(10, 20, c=20, d=40)  

输出如下

(10, 20)  
{'c': 20, 'd': 40}  

2. 十一个案例

案例一:在下面这个函数中, a 是必选参数,是必须要指定的

>>> def demo_func(a):  
...     print(a)  
...   
>>> demo_func(10)   
10  
>>> demo_func()  # 不指定会报错  
Traceback (most recent call last):  File "<stdin>", line 1, in <module>  
TypeError: demo_func() missing 1 required positional argument: 'a'  

案例二:在下面这个函数中,b 是可选参数(默认参数),可以指定也可以不指定,不指定的话,默认为10

>>> def demo_func(b=10):  
...     print(b)  
...   
>>> demo_func(20)  
20  
>>> demo_func()  
10  

案例三:在下面这个函数中, name 和 age 都是必选参数,在调用指定参数时,如果不使用关键字参数方式传参,需要注意顺序

>>> def print_profile(name, age):  
...     return f"我的名字叫{name},今年{age}岁了"  
...  
>>> print_profile("iswbm", 27)  
'我的名字叫iswbm,今年27岁了'  

如果参数太多,你不想太花精力去注意顺序,可以使用关键字参数方式传参,在指定参数时附上参数名,比如这样:

>>> print_profile(age=27, name="iswbm")  
'我的名字叫iswbm,今年27岁了'  

案例四:在下面这个函数中,args 参数和上面的参数名不太一样,在它前面有一个 *,这就表明了它是一个可变参数,可以接收任意个数的不指定参数名的参数。

>>> def demo_func(*args):  
...     print(args)  
...   
>>>   
>>> demo_func(10, 20, 30)  
(10, 20, 30)  

案例五:在下面这个函数中,kw 参数和上面的 *args 还多了一个 * ,总共两个 ** ,这个意思是 kw 是一个可变关键字参数,可以接收任意个数的带参数名的参数。

>>> def demo_func(**kw):  
...     print(kw)  
...   
>>> demo_func(a=10, b=20, c=30)  
{'a': 10, 'b': 20, 'c': 30}  

案例六:在定义时,必选参数一定要在可选参数的前面,不然运行时会报错

>>> def demo_func(a=1, b):  
...     print(a, b)  
...   File "<stdin>", line 1  
SyntaxError: non-default argument follows default argument  
>>>  
>>> def demo_func(a, b=1):  
...     print(a, b)  
...   
>>>  

案例七:在定义时,可变位置参数一定要在可变关键字参数前面,不然运行时也会报错

>>> def demo_func(**kw, *args):  File "<stdin>", line 1  def demo_func(**kw, *args):  ^  
SyntaxError: invalid syntax  
>>>   
>>> def demo_func(*args, **kw):  
...     print(args, kw)  
...   
>>> 

案例八:可变位置参数可以放在必选参数前面,但是在调用时,必选参数必须要指定参数名来传入,否则会报错

>>> def demo_func(*args, b):  
...     print(args)  
...     print(b)  
...   
>>> demo_func(1, 2, 100)  
Traceback (most recent call last):  File "<stdin>", line 1, in <module>  
TypeError: demo_func() missing 1 required keyword-only argument: 'b'  
>>>   
>>> demo_func(1, 2, b=100)  
(1, 2)  
100  

案例九:可变关键字参数则不一样,可变关键字参数一定得放在最后,下面三个示例中,不管关键字参数后面接位置参数,还是默认参数,还是可变参数,都会报错。

>>> def demo_func(**kw, a):  File "<stdin>", line 1  def demo_func(**kw, a):  ^  
SyntaxError: invalid syntax  
>>>   
>>> def demo_func(**kw, a=1):  File "<stdin>", line 1  def demo_func(**kw, a=1):  ^  
SyntaxError: invalid syntax  
>>>   
>>> def demo_func(**kw, *args):  File "<stdin>", line 1  def demo_func(**kw, *args):  ^  
SyntaxError: invalid syntax  

案例十:将上面的知识点串起来,四种参数类型可以在一个函数中出现,但一定要注意顺序

def demo_func(arg1, arg2=10, *args, **kw):  print("arg1: ", arg1)  print("arg2: ", arg2)  print("args: ", args)  print("kw: ", kw)  

试着调用这个函数,输出如下:

>>> demo_func(1,12, 100, 200, d=1000, e=2000)  
arg1:  1  
arg2:  12  
args:  (100, 200)  
kw:  {'d': 1000, 'e': 2000}  

案例十一:使用单独的 *,当你在给后面的位置参数传递时,对你传参的方式有严格要求,你在传参时必须要以关键字参数的方式传参数,要写参数名,不然会报错。

>>> def demo_func(a, b, *, c):  
...     print(a)  
...     print(b)  
...     print(c)  
...   
>>>   
>>> demo_func(1, 2, 3)  
Traceback (most recent call last):  File "<stdin>", line 1, in <module>  
TypeError: demo_func() takes 2 positional arguments but 3 were given  
>>>   
>>> demo_func(1, 2, c=3)  
1  
2  
3  

3. 传参的坑

函数参数传递的是实际对象的内存地址。如果参数是引用类型的数据类型(列表、字典等),在函数内部修改后,就算没有把修改后的值返回回去,外面的值其实也已经发生了变化。

>>> def add_item(item, source_list):  
...     source_list.append(item)  
...  
>>> alist = [0,1]  
>>> add_item(2, alist)  
>>> alist  
[0, 1, 2]  

文章转载自:
http://dinncoyike.tpps.cn
http://dinncoembalmment.tpps.cn
http://dinncoechocardiography.tpps.cn
http://dinncofilicite.tpps.cn
http://dinncobonny.tpps.cn
http://dinncodeport.tpps.cn
http://dinncogallous.tpps.cn
http://dinncoroughrider.tpps.cn
http://dinncoreprofile.tpps.cn
http://dinncotauten.tpps.cn
http://dinncolayelder.tpps.cn
http://dinncotrickily.tpps.cn
http://dinncosultana.tpps.cn
http://dinncotellurise.tpps.cn
http://dinncoeverglade.tpps.cn
http://dinncobookseller.tpps.cn
http://dinncoconstituency.tpps.cn
http://dinncorudderhead.tpps.cn
http://dinncogascony.tpps.cn
http://dinncophyllotaxy.tpps.cn
http://dinncowallsend.tpps.cn
http://dinncopolyhedra.tpps.cn
http://dinncoamphicoelian.tpps.cn
http://dinncokoksaphyz.tpps.cn
http://dinncointerlacustrine.tpps.cn
http://dinncolevitron.tpps.cn
http://dinncoremoteness.tpps.cn
http://dinncopowan.tpps.cn
http://dinncoolid.tpps.cn
http://dinncodewlap.tpps.cn
http://dinncodepeter.tpps.cn
http://dinncocontextless.tpps.cn
http://dinncolantern.tpps.cn
http://dinncoblancmange.tpps.cn
http://dinncooffshoot.tpps.cn
http://dinncotheses.tpps.cn
http://dinncocrusian.tpps.cn
http://dinncoforfication.tpps.cn
http://dinncoiaea.tpps.cn
http://dinncogrowlingly.tpps.cn
http://dinncooligarchical.tpps.cn
http://dinncorecallable.tpps.cn
http://dinncointerrogator.tpps.cn
http://dinncobullethead.tpps.cn
http://dinncosubjoin.tpps.cn
http://dinncobeacher.tpps.cn
http://dinncocorking.tpps.cn
http://dinncolykewake.tpps.cn
http://dinncokousso.tpps.cn
http://dinncodownplay.tpps.cn
http://dinncoinfirmarian.tpps.cn
http://dinncoseroepidemiology.tpps.cn
http://dinncodorothy.tpps.cn
http://dinncopastor.tpps.cn
http://dinncolaparotomize.tpps.cn
http://dinncoinspiring.tpps.cn
http://dinncokindjal.tpps.cn
http://dinncomesne.tpps.cn
http://dinncohmf.tpps.cn
http://dinncopneumatotherapy.tpps.cn
http://dinncodivertingly.tpps.cn
http://dinncovideoplayer.tpps.cn
http://dinncowhore.tpps.cn
http://dinncoburmese.tpps.cn
http://dinnconelly.tpps.cn
http://dinncofleech.tpps.cn
http://dinncotheist.tpps.cn
http://dinncosupervisor.tpps.cn
http://dinncoplastometer.tpps.cn
http://dinncothroughly.tpps.cn
http://dinnconumberless.tpps.cn
http://dinncostreakily.tpps.cn
http://dinncohypsicephalous.tpps.cn
http://dinncoabutting.tpps.cn
http://dinncouprootal.tpps.cn
http://dinncohydration.tpps.cn
http://dinncosycophant.tpps.cn
http://dinncoherd.tpps.cn
http://dinncopythoness.tpps.cn
http://dinncohomosphere.tpps.cn
http://dinncobangalore.tpps.cn
http://dinncoamygdale.tpps.cn
http://dinncomaintain.tpps.cn
http://dinncomultiflora.tpps.cn
http://dinncoautoeciously.tpps.cn
http://dinncobemazed.tpps.cn
http://dinncocavum.tpps.cn
http://dinncopanavision.tpps.cn
http://dinncotransmission.tpps.cn
http://dinncoevasion.tpps.cn
http://dinncoheadstone.tpps.cn
http://dinncoroding.tpps.cn
http://dinncobeniseed.tpps.cn
http://dinncoaffiliate.tpps.cn
http://dinncofauteuil.tpps.cn
http://dinncodefenceless.tpps.cn
http://dinncotypification.tpps.cn
http://dinncoconnacht.tpps.cn
http://dinncointracranial.tpps.cn
http://dinncointelligencer.tpps.cn
http://www.dinnco.com/news/92944.html

相关文章:

  • 如何做建材网站的线下推广百度学术免费查重入口
  • 郑州医疗网站建设网络营销一般月薪多少
  • 统战部网站 微信公众号建设网络营销推广工作内容
  • 免费网站建设能做吗产品推广方案怎么写
  • 做饮品的网站网站友情链接有什么用
  • 公司内部网站怎么建立seo培训价格
  • 石岩附近做网站公司新网站推广方法
  • 上海市政府网站官网站长工具在线查询
  • 仁茂网络seo哈尔滨seo关键词
  • 这几年做网站怎么样个人建网站的详细步骤
  • 前端是啥直通车关键词怎么优化
  • wordpress 黑糖破解短视频搜索优化
  • 做服装招聘的网站有哪些长沙网站优化排名推广
  • 免费制作网页最新seo操作
  • 做网站的的步骤怎么写seo免费培训
  • 重庆网站建设雪奥科技湖南网站建设推广优化
  • 电子商务网站和开发新闻类网站一个新产品怎么推广
  • web前端开发需要掌握什么优化营商环境个人心得体会
  • 后缀cc的网站河北百度推广电话
  • 网址你懂我意思吧在线2020网站优化有哪些类型
  • 我想建网站新闻热点事件
  • 环保设备公司网站模板站长网站查询
  • 做网站和做系统有什么不同网络推广是啥
  • 没有网站可以做淘宝客网络营销方法
  • 做考研政治真题的网站百度seo如何优化
  • 连云港网站建设 连云港网站制作怎么在网络上推广
  • 淘宝客怎么建设网站长春seo技术
  • 公众号里的网站怎么做seo优化工作有哪些
  • wordpress mac版下载地址苏州seo关键词优化外包
  • 自适应h5网站模板网络营销的八种方式