代碼:上的方法是沒有意義的
def solve_the_input(port):
port = hex(int(port))
split_result = port.split("0x")
split_port = split_result[1]
print 'input port is ',split_port
split_port.upper()
print 'input port is ',split_port
return split_port
if __name__ == "__main__":
if len(sys.argv) == 1:
print "please input a port"
else:
port = solve_the_input(sys.argv[1])
輸入
python test.py 42328
實際輸出:
input port is a558
input port is a558
預計輸出:
input port is a558
input port is A558
我不知道爲什麼預期上()方法是行不通的。
蟒蛇的基本規則:字符串方法不會改變字符串 - 他們不能因爲字符串是不可變的(只讀) - 所以他們總是返回一個新的字符串對象。 – cdarke