Loading

邢栋博客

“程序积累“

python2.7 使用print('xingdong',end='')报错

python2.7 使用print('xingdong',end='')报错,是因为这个是python3的方法,如果非要使用,就导入 新的print函数,只要在文件的开头加上 from future import print_function 就可以了这样print函数就和python3一样了,print('hello',end='')就不会出错了 包含end='' 作为print() BIF的一个参数会关闭其默认行为(就是在输入的时候自动包含换行)

python学习笔记生成表格和内容

字符串可以通过 % 进行格式化,用指定的参数替代%s。字符串的join()方法可以把一个 list 拼接成一个字符串。 d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 } def generate_tr(name, score): if score<60: return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score) ...

运行python报错#SyntaxError: Non-ASCII character '\xe6' in file....

运行python报错#SyntaxError: Non-ASCII character '\xe6' in file.... , 原因python文件里含有中文,只要在文件的开头加上 #encoding: utf-8 即可。

python学习笔记Dict和Set类型

遍历dict d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 } for x in d: print x,':', d[x] 更新 dict d = { 95: 'Adam', 85: 'Lisa', 59: 'Bart' } print d[95] d[95] = 'action' print d[95] set类型特点 months = set(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'S...

python学习笔记if-elif-else,for,while,break,continue

if-elif-else事例 score = 85 if score>=90: print 'excellent' elif score<90 and score>=80: print 'good' elif score<80 and score>=60: print 'passed' else: print 'failed' for循环事例 计算平均数 L = [75, 92, 59, 68] sum = 0.0 for x in L: sum = sum + x print sum...

python 学习笔记list类型添加删除替换元素

原始: L = ['php','java','c++'] print L 增加: L.append('ios') print L # ['php','java','c++','ios'] 增加: L.insert(2,'android') print L # ['php','java','android','c++','ios'] 删除 L.pop() print L # ['php','java','android','c++'] 替换 L[-1] = 'cocod2x'; print L #['php','java','android','coco...

ios描述文件生成配置安装

ios描述文件生成配置安装 下载链接1 百度云盘 点击下载 下载链接2 网址 点击下载

json_encode()转码中文显示不正常解决办法

php5.4以上版本. json_encode($data,JSON_UNESCAPED_UNICODE)

php获得字符串内字符的个数(包含中文)

function getstrlen($str,$charset="utf-8") { $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x...

php截取字符串函数(兼容中文或中英文字符串)

function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { if(function_exists("mb_substr")) $slice = mb_substr($str, $start, $length, $charset); elseif(function_exists('iconv_substr')) { $slice = iconv_substr($str,$star...