想要使用IDLE输入“#”

时间:2016-11-09 19:40:45

标签: python-3.x encoding python-idle

我正在使用IDLE,对于我正在编写的脚本,我需要能够输入#。使用IDLE执行代码,#即使作为输入也显示为红色,就像用于编写注释时一样。怎么能解决这个问题?我不太熟悉各种编码等等,希望找到一种方法让它与IDLE一起工作。

2 个答案:

答案 0 :(得分:1)

您使用的是哪种版本的Python IDLE?下面的代码是用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
>>> 

希望有所帮助。

答案 1 :(得分:1)

只需输入您要输入的字符串即可。不需要“解决方法”。这是一个次要bug,IDLE将语法着色应用于输入响应,但除了分心之外,它是无害的。

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