跳到主要內容

發表文章

目前顯示的是 11月, 2014的文章

Python Study (8) – Function

Introduction Function is a Python’s basic structure. Function often is used to reuse code. you can repeat task that define a function for code reuse. Function Advantage  (1) Maximizing code reuse and minimizing redundancy      In developing software,  don't repeat yourself is a a principle . We use function to achieve the goal in Python.A section code is adopted many times or offer other to use. We need to package to a function and offer many time for reuse . (2) Procedural decomposition A flow program is combined from Function component  (1) def Syntax def name(arg1, arg2….) :     statements … Example def add(a, b):            print(a+b) >>>add(1,2) 3 (2) return Syntax def name(arg1, arg2….) :     statements … return result Example def add(a, b): return a+b >>>print(add(1,2)) 3 (3) lambda      lambda is...

Python Study (7) – Statements

Introduction Programming statements are used to expresse action or assign a variable in program.Each statement  has own syntax and purpose. We can combine these statements to achieve specific purpose. Assignment Statements Assingment statement is used to set reference of object or value stored in monery address by a variable name. (1) normal assignment : fruit = “apple” (2) sequence assignment:  a,b = 'Jack', 'John' (3) List assignment : (4) Augmented assignment:      >>>a =1      >>>a+=1 (5) Sequence assignment Sequence one to one >>>seq = [1, 2, 3, 4] >>> a,b,c,d = seq >>> a,b = seq  #seq have 4 elements, but assignemnt elements just have 2 Traceback (most recent call last):   File "<pyshell#9>", line 1, in <module>     a,b = seq ValueError: too many values to unpack (expected 2) >>> a,b,c,d = seq >>>a 1 Sequence one and rest...

Python Study (4)– Dynamic type

Introduction In many programs, You need to declare data type to tell compiler, but  you don’t do it  in Python. It are determined automatically at runtime.   >>> a = “hellow ”    # without delcaring data type            Assigning variable  1. Create an object 2. Create an variable 3. Create reference variable to object Example : The example create a variable and named “a”, then assign enough space to the object. the variable link to the object as reference. >>> a = “hellow ”                Example: The float object is value 1.2 and tell python the object is a float-point-number at first assignment. >>> a =  1.2          # first assign >>> a =  2             # second reassign...

Python Study (5)– String Type

Introduce to string type  ASCII is a sample form of Unicode text, but many text may be not non-English-text source.File working in two modes are  text and bytes ,We need to understand differnt of String of object type in Python3.X and Python 2.X.  Python3.X :     (1) str           : handle text of Unicode form     (2) bytes       : handle binary data     (3) bytearray : handle mutable variant of bytes Python2.x:    (1) str           :  handle 8-bits text and binary data    (2) unicode    :  hanlde Unicode text    (3) bytearray  : handle mutable variant of bytes. ( support 2.6 or later) 1.String Basics  Everything is string.String can be used to represent informations of all kinds(e.g. profile, song…), these informations can be encoded a...

JAVA 字串格式化

應 用 時 機  在日常生活中,常看到文字的格式為日期、時間、貨幣或是特定格式輸出等等,在Java中可以使用formatter來自訂字串的格式。我們可以分為這五種轉換形態 1. 常規 : 一般文字格式 2. 字元 : 顯示字元的型態,char、byte、short 3. 日期/時間 : 用來輸出date、time、calendar等等 4. 百分比: 輸出百分比型態,以百分比表示 ”%” 5. 換行符號: 換行符號(\n) 6. 數字: 用來可以輸出數字 1.常 規 格 式 化  格式符號 說明 - 最小寬度內左對齊,不可0使用 # 用在8進位與16進位的表式 + 空白 正號加空格,負號加- 0 不足填零補足 , 每三位數字,加上, ( 參數為負,以括號把數字刮起來 以下實例可以指定輸出的對象,這種特殊格式以%index$來做指定,下列範例是將a和b對調顯示 p ublic static void main(String[] args) {       //宣告變數       int a = 10 ;       int b = 20 ;       int c = 30 ;             System.out.printf("%d %d %d \n",a,b,c);   //正常顯示             //使用format物件       Formatter format = new Formatter() ;       System.out.println(format.format("%2$d %1$d %3$d", a, b, c))...