2012年9月3日 星期一

Python String Operation Practice

'''
Created on 2012/8/31
Second Python program - String 
@author: Andy Liu
'''

if __name__ == '__main__': 
    str1='Hello '
    str2="World !"
    str3=str1+str2 #combine
    str4=str1*2 #double
    str5=str4.replace(" Hello"," World !") #replace string
    print(str1)
    print(str2)
    print(str3)
    print(str4)
    print(str5)
    print "Hello" in str4
    print "!" in str4
    print(len(str4)) #string length
    print(str3.split(" ")) #split String
    print(dir(str1)) # string type character
    pass
執行結果
Hello 
World !
Hello World !
Hello Hello 
Hello World ! 
True
False
12
['Hello', 'World', '!']
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

沒有留言:

[Excel]如何創建自定義函數

在 Excel 內建函式中找不到自已想要的函式怎麼辦?事實上我們可以自已建一個,以下是一個簡單的Excel自定義函數示例,用於將民國年轉為西元: Function 民國轉西元(x As Double) As Double     民國轉西元 = x + 1911 End Func...