Python for Ruby Programmers.pdf

Python for Ruby Programmers.pdf

ID:33933326

大小:1.52 MB

页数:130页

时间:2019-03-01

Python for Ruby Programmers.pdf_第1页
Python for Ruby Programmers.pdf_第2页
Python for Ruby Programmers.pdf_第3页
Python for Ruby Programmers.pdf_第4页
Python for Ruby Programmers.pdf_第5页
资源描述:

《Python for Ruby Programmers.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、PythonforRubyProgrammersMIKELEONELARUBYCONF2013FEB232013Thispresentation:1.Fast-paced2.Pythonin30mins3.It'seasy!AboutMeWebMobileEmbeddedThat'sit.Ruby:2006Python:2010NewappreciationBetterRubyistWhatwe'llcover1.Exampleprogram2.13Designsimilarities3.13Differences4.5Problemdomains5.“Feelings”WhatweWON'

2、Tcover1.Implementations2.Performance(Goodenough)3.Parallelism(GIL)4.Minorsyntax(You'llgetit)WhatI'lltrytoconvinceyou:1.VERYsimilar!2.You'realreadyready3.Python=BetterRubyist4.HireaPythonistaZenofPython(abridged)1.Explicitisbetterthanimplicit.2.Flatisbetterthannested.3.Readabilitycounts.4.Thereshoul

3、dbe[only]oneobviouswaytodoit.5.Namespacesareagreatidea--let'sdomoreofthose!Example:CreateaPersonclass1.Nameandage2.Cangreetyou3.Knowsifit'sBeiber4.GreetsGoogledirectors13Similarities1.DynamicallyTypeddefprint_object(some_sorta_object):printsome_sorta_object.read()print_object(my_file)>>>“Thisisthef

4、ilecontents”2.EverythingisanObject(evenfunctions!)Pythonexample:5+3>>>8(5).__add__(3)>>>8(5).__str__()>>>“5”3.ArraysRuby(array)things=[1,"hello",2.5,43]things[1]>>'hello'Python(list)things=[1,"hello",2.5,43]things[1]>>'hello'4.HashTablesRuby(hash)color_map={red:"#FF0000",purple:"#800080"}color_map[

5、:red]>>"#FF0000"Python(list)color_map={"red":"#FF0000","purple":"#800080"}color_map["red"]>>"#FF0000"5.Nospeciallineterminators(nosemicolons!)6.StrongfunctionalprogrammingparadigmsMapdeftriple(number):returnnumber*3list=[1,2,3,4]map(triple,list)>>>[3,6,9,12]Filterdefis_even(number):returnnumber%2==

6、0list=[1,2,3,4]filter(is_even,list)>>>[2,4]AnonymousFunctions(lambda)list=[1,2,3,4]map(lambdax:x*3,list)>>>[3,6,9,12]7.AwesomefunctionparametersOptional/namedargumentsdefgreet(name,greeting="Hello"):printgreeting+","+namegreet("Bob")>>>Hello,Bobgreet("Bob",greeting="Bonjour")>>>Bonjour,Bobgreet("Bo

7、b","Bonjour")>>>Bonjour,BobArgumentUnpackingdefgreet_everyone(*names):fornameinnames:print"Hello,"+namenames=["Bob","Steve","Jim"]greet_everyone(*names)Hello,BobHello,SteveHello,Jim8.RaisingExceptionsRubyin

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。