最近要練習寫python,
# Result:
alex is starting to learn "python"
# Result:
<Blur1 at 0x00000000054BD850>
print type(varalex)
# Result:
<type 'int'>
print abs(varalex)
# Result:
5
print mystring
# Result:
alex hello
取質
mystring = 'alex'
mystring += ' hello'
print mystring[0]
# Result:
a
print mystring[2:-1]
# Result:
ex hell
變大寫
mystring = 'ALEX'
mystring += ' hello'
print mystring.upper()
# Result:
ALEX HELLO
print mystring.upper()[2:-1]
# Result:
EX HELL
變小寫
mystring = 'ALEX'
mystring += ' hello'
print mystring.lower()
# Result:
alex hello
print mystring.lower()[2:-1]
# Result:
ex hell
說明幫助
help(*****) ***填上要說明的物件
ex:
help(nuke)
help(str)
分段
varalex = 'today is a good day to learn python'
print varalex.split(' ')
# Result:
['today', 'is', 'a', 'good', 'day', 'to', 'learn', 'python']
mystring = 'ALEX'
mystring += ' hello'
vralex = mystring.lower()[2:-1]
print vralex.split(' ')
# Result:
['ex', 'hell']
split(填入判別的字元)
檢查開始字元
mystring = 'ALEX'
mystring += ' hello'
vralex = mystring.lower()[2:-1]
print vralex.startswith('e')
# Result:
True
檢查最後的字元
mystring = 'ALEX'
mystring += ' hello'
vralex = mystring.lower()[2:-1]
print vralex.endswith('ell')
# Result:
True
留言列表