from:http://www.unixresources.net/linux/clf/python/archive/00/00/42/73/427317.html結合二位的回覆,運行結果如下: >>> a='中國' >>> b=unicode(a, 'cp936') >>> b u'u4e2du56fd' >>> c = b.encode('utf-8') >>> c
通常,一個程式都會有輸入/輸出,這樣可以與使用者進行互動。使用者輸入一些資訊,你會對他輸入的內容進行一些適當的操作,然後再輸出給使用者想要的結果。Python的輸入/輸出,我們可以用input進行輸入,print進行輸出,這些都是簡單的控制台輸入/輸出,複雜的有處理檔案等。1. input和printname = input("Please input your name:\n")print("Hello,", name)運行結果:Please input your
Variables declared inside the class definition, but not inside a method are class or static variables:>>> class MyClass: ... i = 3 ... >>> MyClass.i 3 As @Daniel points out, this creates a class-level "i" variable, but this is
import re # Validate logs from admd. Have "from" and have comma. It mean both "client IP" and "denied reason" is given by appliance. def validate_re1(): print 'The following test case should succeed: ' regex = 'user\s+\[(\S+)\]\s+from\s+(\d+\
指令碼:#!/usr/bin/python dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print "###########items#####################" for (k,v) in dict.items(): p
http://www.cnblogs.com/way_testlife/archive/2010/06/14/1758276.html#第一個:求 50 - 100 之間的質數import mathfor i in range(50, 100 + 1): for j in range(2, int(math.sqrt(i)) + 1): if i % j == 0: break else: print