2016-11-09 42 views
0

我使用IDLE和劇本我寫我需要能夠輸入#。使用IDLE執行代碼時,#即使是輸入時也會顯示爲紅色,就像它用於寫評論時一樣。這怎麼解決?我不太熟悉各種編碼等,希望找到一種方法使其與IDLE協同工作。想要輸入「#」使用IDLE

您正在使用什麼版本的Python IDLE的
+0

你試過把它放在字符串文字中嗎? –

+0

正如書面'#'一樣?或者你的意思是str(#)? – user1036197

回答

1

只需輸入你想輸入的字符串。沒有「解決方法」是必要的。它是一個小的bug,IDLE應用語法着色來輸入響應,但除了分心之外它是無害的。

>>> s = input(': ') 
: #@%!#  
>>> s 
'#@%!#' 
+0

非常感謝,顏色讓我分心,認爲它不會被接受爲一個字符串。正如你所說,它工作得很好。非常感謝。 – user1036197

1

?下面的代碼是用Python 3.5.2 IDLE

>>> # declare the user input and assign a placeholder variable 
>>> user_input = ' ' 
>>> while user_input != 'end': 
    # get user input until the user input the word end 
    user_input = input('>> ') 
    # as long as the word end is not entered print the input results 
    if user_input != 'end': 
     print(user_input) 

產生以下輸出:

>> # 
# 
>> ## 
## 
>> What is the # 
What is the # 
>> What format would you like the time in ##:##:## 
What format would you like the time in ##:##:## 
>> Print some ###### 
Print some ###### 
>> end 
>>> 

希望有所幫助。