#查询文件中含有特殊字符串的行 #!/usr/bin/python # -*- coding:utf- -*- import re file1 = open('test.txt','r+') istxt = re.compile(r'.*if.*',re.I) for line in file1.readlines(): line = line.strip() ifstr = re.findall(istxt,line) if ifstr: print ifstr #删除特定行(创建新文件,把不
python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c)+1 print "the second" result = [ord(c)+1 for c in a_string] print result print "the thrid" def do_something(c): return ord(c)+1 result
打印菱形图案: 代码实现: public class Hello { public static void main(String args[]) { LingXingPrint("#", 7); } public static void LingXingPrint(String i, int num) { /** * 打印菱形,传参:i 为打印的字符,num为行数 . * 思路:将菱形分为上三角和下三角,上三角:每一行空格打印数为总行数-行号:每一行字符打印个数为2*行号-1;下三角