SlideShare une entreprise Scribd logo
1  sur  43
从JavaScript到Python yingjie.wuyj@alibaba-inc.com
Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
什么是Python? Python语言是在1989年由 Guido van Rossum开发的 免费、开源、跨平台 全球10大编程语言之一
什么是Python? Python特性 易用性 免费、开源 跨平台 动态 面向对象 易于扩展
什么是Python? Python可以做什么 计算器 处理文本 网络编程 数据库编程 科学计算 多媒体处理 图形界面 Windows编程 …
什么是Python? If programming languages are  cars.. Python is a great beginner’s car; you can drive it without a license. Unless you want to drive really fast or on really treacherous terrain, you may never need another car.
排名
谁在用Python?
Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
与众不同之处 排版 几个例子 奇技淫巧
与众不同之处 排版格式,缩进有语法意义 变量不需要定义
交换变量的值 JavaScript var a = 1, b = 2; vartmp = a; a = b; b = tmp; Python a = 1 b = 2 a, b = b, a
判断数字范围 JavaScript if (a > 3 && a < 6) { … } Python if 3 < a < 6: …
计算阶乘 n! JavaScript function factorial(n) { 	return n != 1 ? n * factorial(n - 1) : 1; } factorial(n); Python reduce(lambda x, y: x * y, range(1, n + 1))
找出一个数组中的所有偶数 JavaScript var a = [12, 5, 2, 60, 55, 6, 33, 9], b = []; for (vari = 0; i < a.length; i ++) { 	if (a[i] % 2 == 0) b.push(a[i]); } Python a = [12, 5, 2, 60, 55, 6, 33, 9] b = [i for i in a if i % 2 == 0]
大数处理 计算2的10000次方 >>> 2 ** 10000 19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376 共3011位
一个函数返回多个值 def func(): ...... return val_1, val_2 a, b = func()
计算一个文本文件中最长的一行有多长 max(len(x.strip()) for x in open('test.txt'))
Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
一点点语法 变量 语句 函数
一点点语法 变量 数字 字符串 列表和元组(相当于JS中的Array) 字典(相当于JS中的Object) 集合
一点点语法 变量 数字 实数 整数 10000位的大整数 2 的 10000 次方 浮点小数 虚数 3 + 4j
一点点语法 变量 字符串 字符串不可改变 具有类似数组的功能 s = “abcdefg” s[0]    “a”
一点点语法 变量 列表和元组(相当于JS中的Array) 列表 [1, 2, 3, “a”, “bbc”] [3.14, [1, 3, 5], “aa”] 元组 (1, 2, 3, “a”, “bbc”) 元组不可改变
一点点语法 变量 字典(相当于JS中的Object) dic = { 	“a”: 1, 	“b”: 2, 	“c”: 3, }
一点点语法 变量 集合 介于元组和字典之间 >>> s = set() >>> s.add("a") >>> s.add("b") >>> s.add("c") >>> s.add("a") >>> s set(['a', 'c', 'b'])
一点点语法 语句 if for while
一点点语法 语句 没有“?:”三元操作符
一点点语法 函数 def lambda 闭包
一点点语法 函数 def >>> def f(a): ...     b = a * 2 ...     return b ... >>> f(3) 6
一点点语法 函数 lambda 匿名函数 >>> f = lambda x: x * 2 >>> f(3) 6
一点点语法 函数 闭包 >>> def f(a): ...     b = a * 2 ...     def g(): ...         c = b * 2 ...         return c ...     return g() ... >>> f(3) 12
一点点语法 函数 闭包 >>> def f(a): ...     b = a * 2 ...     def g(): ...         b = b * 2 ...         return b ...     return g() ... >>> f(3) Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "<stdin>", line 6, in f   File "<stdin>", line 4, in g UnboundLocalError: local variable 'b' referenced before assignment
Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
好玩的例子 小爬虫 图片批量下载 树
好玩的例子 小爬虫 下载指定页面的HTML >>> import urllib >>> u = urllib.urlopen("http://china.alibaba.com/") >>> html = u.read() >>> print html <!doctype html public "-//w3c//dtdxhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>         <title>阿里巴巴是全球领先的B2B电子商务网上贸易平台</title>         <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>         <meta http-equiv="X-UA-Compatible" content="IE=7" /> <meta name="verify-v1" content="fY3J3JK21Xt98skDWznPEIQE+Vle91rbRHkvUk07/WE=" />         <meta name="description" content=... >>> u.close()
好玩的例子 图片批量下载 import urllib import re import os u = urllib.urlopen("http://china.alibaba.com/") html = u.read() u.close() imgs = re.findall("http://[^quot;]*?(?:jpg|gif|png)",br />	html, re.I) for img_src in imgs: 	fn = os.path.split(img_src)[1] img_bin = urllib.urlopen(img_src).read() 	f = open(fn, “wb”) f.wirte(img_bin) f.close()
好玩的例子 树
Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
Pythonic Python is powerful... and fast Python plays well with others Python runs everywhere Python is friendly... and easy to learn Python is Open
Pythonic >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
Tnanks! :-)

Contenu connexe

Similaire à Python分享

Client-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesOry Segal
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Steve Souders
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Enterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript DevelopersEnterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript DevelopersAndreCharland
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersAccelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersTodd Anglin
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009marpierc
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPRobertGonzalez
 
Teflon - Anti Stick for the browser attack surface
Teflon - Anti Stick for the browser attack surfaceTeflon - Anti Stick for the browser attack surface
Teflon - Anti Stick for the browser attack surfaceSaumil Shah
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacriptLei Kang
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesTikal Knowledge
 
Developing Gadgets
Developing GadgetsDeveloping Gadgets
Developing GadgetsQuirk
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page CreationWildan Maulana
 

Similaire à Python分享 (20)

Client-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript Vulnerabilities
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
&lt;img src="xss.com">
&lt;img src="xss.com">&lt;img src="xss.com">
&lt;img src="xss.com">
 
Fav
FavFav
Fav
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Fast by Default
Fast by DefaultFast by Default
Fast by Default
 
Enterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript DevelopersEnterprise AIR Development for JavaScript Developers
Enterprise AIR Development for JavaScript Developers
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET DevelopersAccelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
 
Object Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHPObject Oriented Design Patterns for PHP
Object Oriented Design Patterns for PHP
 
Teflon - Anti Stick for the browser attack surface
Teflon - Anti Stick for the browser attack surfaceTeflon - Anti Stick for the browser attack surface
Teflon - Anti Stick for the browser attack surface
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
Developing Gadgets
Developing GadgetsDeveloping Gadgets
Developing Gadgets
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
OSGi with the Spring Framework
OSGi with the Spring FrameworkOSGi with the Spring Framework
OSGi with the Spring Framework
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page Creation
 

Plus de fangdeng

jQuery底层架构
jQuery底层架构jQuery底层架构
jQuery底层架构fangdeng
 
Building an event driven web
Building an event driven webBuilding an event driven web
Building an event driven webfangdeng
 
浅尝jQuery
浅尝jQuery浅尝jQuery
浅尝jQueryfangdeng
 
Html基础培训
Html基础培训Html基础培训
Html基础培训fangdeng
 
前端开发之Js
前端开发之Js前端开发之Js
前端开发之Jsfangdeng
 
Javascript代码注释及文档生成
Javascript代码注释及文档生成Javascript代码注释及文档生成
Javascript代码注释及文档生成fangdeng
 
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架fangdeng
 
前端单元测试初体验
前端单元测试初体验前端单元测试初体验
前端单元测试初体验fangdeng
 
Java script测试之js unit ut
Java script测试之js unit utJava script测试之js unit ut
Java script测试之js unit utfangdeng
 
2011年方凳年度总结及颁奖
2011年方凳年度总结及颁奖2011年方凳年度总结及颁奖
2011年方凳年度总结及颁奖fangdeng
 
产品线中的思考
产品线中的思考产品线中的思考
产品线中的思考fangdeng
 
产品线中的思考
产品线中的思考产品线中的思考
产品线中的思考fangdeng
 
Postoffer前端架构设计
Postoffer前端架构设计Postoffer前端架构设计
Postoffer前端架构设计fangdeng
 
Varnish简介
Varnish简介Varnish简介
Varnish简介fangdeng
 
Let's talk about date in javascript
Let's talk about  date  in javascriptLet's talk about  date  in javascript
Let's talk about date in javascriptfangdeng
 
Test driven-frontend-develop
Test driven-frontend-developTest driven-frontend-develop
Test driven-frontend-developfangdeng
 
方凳良品1期
方凳良品1期方凳良品1期
方凳良品1期fangdeng
 
方凳良品2期
方凳良品2期方凳良品2期
方凳良品2期fangdeng
 
魏琪君-重构-关于可读性、原则和模式
魏琪君-重构-关于可读性、原则和模式魏琪君-重构-关于可读性、原则和模式
魏琪君-重构-关于可读性、原则和模式fangdeng
 

Plus de fangdeng (20)

jQuery底层架构
jQuery底层架构jQuery底层架构
jQuery底层架构
 
Building an event driven web
Building an event driven webBuilding an event driven web
Building an event driven web
 
浅尝jQuery
浅尝jQuery浅尝jQuery
浅尝jQuery
 
Html基础培训
Html基础培训Html基础培训
Html基础培训
 
前端开发之Js
前端开发之Js前端开发之Js
前端开发之Js
 
Javascript代码注释及文档生成
Javascript代码注释及文档生成Javascript代码注释及文档生成
Javascript代码注释及文档生成
 
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
 
前端单元测试初体验
前端单元测试初体验前端单元测试初体验
前端单元测试初体验
 
Java script测试之js unit ut
Java script测试之js unit utJava script测试之js unit ut
Java script测试之js unit ut
 
2011年方凳年度总结及颁奖
2011年方凳年度总结及颁奖2011年方凳年度总结及颁奖
2011年方凳年度总结及颁奖
 
产品线中的思考
产品线中的思考产品线中的思考
产品线中的思考
 
产品线中的思考
产品线中的思考产品线中的思考
产品线中的思考
 
Postoffer前端架构设计
Postoffer前端架构设计Postoffer前端架构设计
Postoffer前端架构设计
 
Varnish简介
Varnish简介Varnish简介
Varnish简介
 
Websocket
WebsocketWebsocket
Websocket
 
Let's talk about date in javascript
Let's talk about  date  in javascriptLet's talk about  date  in javascript
Let's talk about date in javascript
 
Test driven-frontend-develop
Test driven-frontend-developTest driven-frontend-develop
Test driven-frontend-develop
 
方凳良品1期
方凳良品1期方凳良品1期
方凳良品1期
 
方凳良品2期
方凳良品2期方凳良品2期
方凳良品2期
 
魏琪君-重构-关于可读性、原则和模式
魏琪君-重构-关于可读性、原则和模式魏琪君-重构-关于可读性、原则和模式
魏琪君-重构-关于可读性、原则和模式
 

Dernier

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Dernier (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Python分享

  • 2. Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
  • 3. Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
  • 4. 什么是Python? Python语言是在1989年由 Guido van Rossum开发的 免费、开源、跨平台 全球10大编程语言之一
  • 5. 什么是Python? Python特性 易用性 免费、开源 跨平台 动态 面向对象 易于扩展
  • 6. 什么是Python? Python可以做什么 计算器 处理文本 网络编程 数据库编程 科学计算 多媒体处理 图形界面 Windows编程 …
  • 7. 什么是Python? If programming languages are cars.. Python is a great beginner’s car; you can drive it without a license. Unless you want to drive really fast or on really treacherous terrain, you may never need another car.
  • 10. Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
  • 13. 交换变量的值 JavaScript var a = 1, b = 2; vartmp = a; a = b; b = tmp; Python a = 1 b = 2 a, b = b, a
  • 14. 判断数字范围 JavaScript if (a > 3 && a < 6) { … } Python if 3 < a < 6: …
  • 15. 计算阶乘 n! JavaScript function factorial(n) { return n != 1 ? n * factorial(n - 1) : 1; } factorial(n); Python reduce(lambda x, y: x * y, range(1, n + 1))
  • 16. 找出一个数组中的所有偶数 JavaScript var a = [12, 5, 2, 60, 55, 6, 33, 9], b = []; for (vari = 0; i < a.length; i ++) { if (a[i] % 2 == 0) b.push(a[i]); } Python a = [12, 5, 2, 60, 55, 6, 33, 9] b = [i for i in a if i % 2 == 0]
  • 17. 大数处理 计算2的10000次方 >>> 2 ** 10000 19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376 共3011位
  • 18. 一个函数返回多个值 def func(): ...... return val_1, val_2 a, b = func()
  • 20. Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
  • 22. 一点点语法 变量 数字 字符串 列表和元组(相当于JS中的Array) 字典(相当于JS中的Object) 集合
  • 23. 一点点语法 变量 数字 实数 整数 10000位的大整数 2 的 10000 次方 浮点小数 虚数 3 + 4j
  • 24. 一点点语法 变量 字符串 字符串不可改变 具有类似数组的功能 s = “abcdefg” s[0] “a”
  • 25. 一点点语法 变量 列表和元组(相当于JS中的Array) 列表 [1, 2, 3, “a”, “bbc”] [3.14, [1, 3, 5], “aa”] 元组 (1, 2, 3, “a”, “bbc”) 元组不可改变
  • 26. 一点点语法 变量 字典(相当于JS中的Object) dic = { “a”: 1, “b”: 2, “c”: 3, }
  • 27. 一点点语法 变量 集合 介于元组和字典之间 >>> s = set() >>> s.add("a") >>> s.add("b") >>> s.add("c") >>> s.add("a") >>> s set(['a', 'c', 'b'])
  • 30. 一点点语法 函数 def lambda 闭包
  • 31. 一点点语法 函数 def >>> def f(a): ... b = a * 2 ... return b ... >>> f(3) 6
  • 32. 一点点语法 函数 lambda 匿名函数 >>> f = lambda x: x * 2 >>> f(3) 6
  • 33. 一点点语法 函数 闭包 >>> def f(a): ... b = a * 2 ... def g(): ... c = b * 2 ... return c ... return g() ... >>> f(3) 12
  • 34. 一点点语法 函数 闭包 >>> def f(a): ... b = a * 2 ... def g(): ... b = b * 2 ... return b ... return g() ... >>> f(3) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 6, in f File "<stdin>", line 4, in g UnboundLocalError: local variable 'b' referenced before assignment
  • 35. Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
  • 37. 好玩的例子 小爬虫 下载指定页面的HTML >>> import urllib >>> u = urllib.urlopen("http://china.alibaba.com/") >>> html = u.read() >>> print html <!doctype html public "-//w3c//dtdxhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>阿里巴巴是全球领先的B2B电子商务网上贸易平台</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <meta name="verify-v1" content="fY3J3JK21Xt98skDWznPEIQE+Vle91rbRHkvUk07/WE=" /> <meta name="description" content=... >>> u.close()
  • 38. 好玩的例子 图片批量下载 import urllib import re import os u = urllib.urlopen("http://china.alibaba.com/") html = u.read() u.close() imgs = re.findall("http://[^quot;]*?(?:jpg|gif|png)",br /> html, re.I) for img_src in imgs: fn = os.path.split(img_src)[1] img_bin = urllib.urlopen(img_src).read() f = open(fn, “wb”) f.wirte(img_bin) f.close()
  • 40. Content 什么是Python? 与众不同之处 一点点语法 好玩的例子 Pythonic
  • 41. Pythonic Python is powerful... and fast Python plays well with others Python runs everywhere Python is friendly... and easy to learn Python is Open
  • 42. Pythonic >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!