遍历
python中的for循环很方便,但js中等价的写法 不是 for/in,for/in 语句循环遍历对象的属性:如要遍历打印数组的元素js用forEach
python:
>>> a = [1,2,3,4]
>>> for n in a:
print n
javascript:
a = [1,2,3,4]
a.forEach(function(n){
alert(n)
})
闭包
# python 闭包就好像只有一个方法的类 >>> def sandwich_maker(magic_ingredient): def make(filling): return magic_ingredient + ' and ' + filling return make >>> ham_and = sandwich_maker('ham') >>> ham_and('cheese') 'ham and cheese' >>> ham_and('mustard') 'ham and mustard' >>> turkey_and = sandwich_maker('turkey') >>> turkey_and('swiss') 'turkey and swiss' >>> turkey_and('provolone') 'turkey and provolone'
function sandwichMaker(ingredient){ function make(filling){ return ingredient + ' and ' + filling; } return make } var hamAnd = sandwichMaker('ham') hamAnd('cheese') "ham and cheese" hamAnd('mustard') "ham and mustard" var turkeyAnd = sandwichMaker('turkey'); turkeyAnd('swiss') "turkey and swiss" turkeyAnd('Provolone') "turkey and Provolone"
但是在python中我觉得完全可以用类来写,看着更习惯吧,在js中函数就是类,在python中这样想也好理解
>>> class SandwichMaker(): def __init__(self, magic_ingredient): self.magic_ingredient = magic_ingredient def make(self, filling): return self.magic_ingredient + ' and ' + filling def make2(self, filling): return self.magic_ingredient + ' and ' + filling >>> ham_and = SandwichMaker('ham') >>> ham_and.make('cheese') 'ham and cheese' >>> ham_and.make('mustard') 'ham and mustard' >>> turkey_and = SandwichMaker('turkey') >>> turkey_and.make('swiss') 'turkey and swiss' >>> turkey_and.make('provolone') 'turkey and provolone' # 把类改成函数是不是很像,但方法多了调用起来麻烦,所以类就是一个改造过的函数 >>> def SandwichMaker(magic_ingredient): magic_ingredient = magic_ingredient def make(filling): return magic_ingredient + ' and ' + filling def make2(filling): return magic_ingredient + ' and ' + filling return make, make2 >>> ham_and = SandwichMaker('ham') >>> ham_and[0]('cheese') 'ham and cheese' >>> ham_and[0]('mustard') 'ham and mustard' >>> turkey_and = SandwichMaker('turkey') >>> turkey_and[0]('swiss') 'turkey and swiss' >>> turkey_and[0]('provolone') 'turkey and provolone' >>>
相关推荐
Learn how to turn raw data into rich, interactive web visualizations with the powerful combination of Python and JavaScript. With this hands-on guide, author Kyran Dale teaches you how build a basic ...
脚本 PScript是Python到JavaScript的编译器,也是该编译器支持的Python子集的名称。 它是作为的一部分开发的(作为flexx.pyscript ),现在由其自己的项目表示。 尽管它仍然是Flexx的重要组成部分,但它本身也可以...
You'll also receive updates when significant changes are made, new chapters are available, and the final ebook bundle is released., Python and Javascript are the perfect complement for turning data ...
Data Visualization with Python and JavaScript 2017-03-17: Second Release
基于python+JavaScript实现显示文件的二进制图表(软件构造大作业).zip基于基于python+JavaScript实现显示文件的二进制图表(软件构造大作业).zip基于python+JavaScript实现显示文件的二进制图表(软件构造大作业).zip...
软件工程课设-基于python和JavaScript的汽车充电管理系统设计源码.zip软件工程课设-基于python和JavaScript的汽车充电管理系统设计源码.zip软件工程课设-基于python和JavaScript的汽车充电管理系统设计源码.zip软件...
JavaScript到Python编译器和JavaScript解释器,用100%纯Python编写
基于Python+JavaScript+vue+css的开源量化交易平台开发框架,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用~ 基于Python+JavaScript+vue+css的开源量化交易平台...
Data-Visualization-with-Python-and-JavaScript-Scrape-Clean-Explore-Transform-Your-Data.pdf
Frappe Framework是Python和JavaScript的全栈Web应用程序框架
CNN可视化解释器:基于Python和Javascript开发,包含89个文件,包括21个JPEG图像文件、19个Svelte组件文件、13个JavaScript文件、9个PNG图像文件、6个SVG图像文件、3个JSON配置文件、3个GIF图像文件、2个Markdown...
Python+JavaScript+html编写的免费刷题工具,可以实现浏览器读取本地excel文件,自定义题库。 软件特色: 1.完全免费使用,没有任何广告插件; 2.实现了浏览器读取本地excel文件,非IE浏览器也可以轻松读取本地文件...
code2flow:把你的 Python 和 JavaScript 代码转换为流程图
Recording personal Java, Python, JavaScript solutions for Leetcode problems. 记录个人 Java, Python, JavaScript 的Leetcode题解.zip
pys:模仿 Python 字符串分片操作的 JavaScript 模块
curlconverter, 将curl命令转换为 python,javascript,php 将curl语法转换为原生 python 和javascript代码实时演示https://curl.trillworks.com安装$ npm install --save curlconverter用法
Pylava是一个用于Python和JavaScript的代码审计工具
JSParser 使用Tornado和JSBeautifier的python 2.7脚本来解析JavaScript文件中的相对URL。 用于在执行安全研究或Bug赏金狩猎时轻松发现AJAX请求。
本项目是基于Python和Javascript的视频播放网站设计源码,共有3268个文件,包括867个PNG文件、738个SVG文件等。系统采用前后端分离的设计,前端使用HTML、CSS、Javascript,后端采用Python和PHP。该系统提供了一个...