想要输入“#”使用IDLE
问题描述:
我使用IDLE和剧本我写我需要能够输入#。使用IDLE执行代码时,#即使是输入时也会显示为红色,就像它用于写评论时一样。这怎么解决?我不太熟悉各种编码等,希望找到一种方法使其与IDLE协同工作。想要输入“#”使用IDLE
您正在使用什么版本的Python IDLE的
答
只需输入你想输入的字符串。没有“解决方法”是必要的。它是一个小的bug,IDLE应用语法着色来输入响应,但除了分心之外它是无害的。
>>> s = input(': ')
: #@%!#
>>> s
'#@%!#'
+0
非常感谢,颜色让我分心,认为它不会被接受为一个字符串。正如你所说,它工作得很好。非常感谢。 – user1036197
答
?下面的代码是用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
>>>
希望有所帮助。
你试过把它放在字符串文字中吗? –
正如书面'#'一样?或者你的意思是str(#)? – user1036197