随笔分类 - 语言python
python
摘要:print '0123'.ljust(20, '-')print '01234'.ljust(20, '-')print '012356'.ljust(20, '-')print '0123567'.ljust(20, '-')
阅读全文
摘要:strVal = "%.2f" % valfloatVal = round(val, 2)但是如果val为1.0, 则结果仍为1.0, 不是1.00
阅读全文
摘要:for index, value in enumerate(list): print index, value
阅读全文
摘要:str1 = ""str2 = Nonestr3 = "hello"if str2: print "not null"else: print "null"这样,不仅可以判定字符串是否为空,还能判定是否为None
阅读全文
摘要:比较中文是否相等:if str1.decode("GB2312").encode("utf-8") ==str2.decode("GB2312").encode("utf-8"): print "=="注: decode中时str1 str2使用的中文编码方式, encode统一用utf-8形式比...
阅读全文
摘要:import rereg = re.compile(r"voip", re.IGNORECASE)print reg.findall("23oipvoipsnvoipc")输出['voip', 'voip']findall() 找到 RE 匹配的所有子串,并把它们作为一个列表返回http://wik...
阅读全文
摘要:import datetimedatetime有几个常用类:date time datetime timedelta1. 今天日期时间(今天时间)>>> import datetime>>> now = datetime.datetime.now()>>> print now2014-06...
阅读全文
摘要:#!/usr/bin/python3class Student(object): def __init__(self): #默认有此函数,自定义时运行自定义的。实例化时首次运行该函数 print("First function to run when create a instance.") def getName(self): self.name = ...
阅读全文
摘要:在python3.0以后的版本中,raw_input和input合体了,取消raw_input,并用input代替,所以现在的版本input接收的是字符串,你可以用:x = int(input("x: "))x = input("input x:")print(int(x)+1)
阅读全文
摘要:def funName(x): print("call funName") return (x + 1)
阅读全文
摘要:for eachNum in [0, 1, 2]: print(eachNum)#range()内建函数生成0 1 2... for eachNum in range(3): print(eachNum) foo = 'abc'for c in foo: print(c)输出:012012abc
阅读全文
摘要:counter = 0while counter < 3: print(counter) counter += 1 print(counter)
阅读全文
摘要:if 2 < 1: print("if")else: print("else") if 2 < 1: print("if")elif 2 == 1: print("elif")else: print("else")
阅读全文
摘要:http://www.cr173.com/html/7367_1.html
阅读全文

浙公网安备 33010602011771号