今天用nodejs进行http请求时返回的数据是一个html文件,然后我还是按照以前解析json数据的方法.果不其然报错了:SyntaxError: Unexpected token in JSON at position 0 没办法,只好换一种方法,将接受到的Buffer对象toString,然后打印出来发现是乱码. 第一感觉是编码问题,google一下然后看官方文档,总结三种方法: 1.toString 加编码格式作为参数. 2.使用iconv-lite 改变编码. 3.使用cheerio
1.脚本 def add(a,b): return (a+b)def div(a,b,c): return (a/b-c)x = div(34,100,1023)y = add(24,x)print ("the result is %f" %y) print ("the result is %d" %y) 2.执行结果 备注 1.利用return可以将函数的值返回 2.%f返回浮点型 3.%d返回整形