'''
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']