1
我試圖將while循環轉換爲for循環,但我不知道如何去做。將一個while循環轉換爲Python中的for循環3.3
output = ''
i = 0
while i <len(MyArray):
C = chr(int(MyArray[i],2))
output = output + C
i = i + 1
print(output)
任何幫助,將不勝感激
我試圖將while循環轉換爲for循環,但我不知道如何去做。將一個while循環轉換爲Python中的for循環3.3
output = ''
i = 0
while i <len(MyArray):
C = chr(int(MyArray[i],2))
output = output + C
i = i + 1
print(output)
任何幫助,將不勝感激
output = ''
for i in range(len(MyArray)):
C = chr(int(MyArray[i],2))
output = output + C
print(output)
或
output = ''
for element in MyArray:
C = chr(int(element,2))
output = output + C
print(output)
或
output = [chr(int(element,2)) for element in MyArray]
print ''.join(output)
嗨,其未來與那個時候我有輸出沒有定義的錯誤試過你的解決方案 – user3250858
是的,它走了在複製你的代碼時丟失了,但它應該是相當明顯的如何解決這個問題:) –
哈哈我的錯,是的人其完美的感謝! – user3250858