如何在用户输入中加入引号?

时间:2016-08-01 07:14:04

标签: python python-2.x

def palindrome(s):
    s=input ("Enter a phrase (**use quotation marks for words**): ")
    s.lower()
    return s[::-1]==s

palindrome(s)

这是我的代码。如何更改它以便我可以取出粗体部分?我使用python 2并且它不接受没有引号的字符串输入。

2 个答案:

答案 0 :(得分:1)

使用raw_input代替input。在Python 2 input尝试评估用户的输入,因此字母被评估为变量。

答案 1 :(得分:1)

<div class="input-group"> <input type="text" id="myval" th:value="*{response.query}" /> <div class="input-group-btn"> <ul class="dropdown-menu dropdown-menu-right"> <li><a href="#" onclick="onReadClick();" href="#">Read</a></li> <li><a href="#" th:href="@{/delete/{id}(id=response.query)">Delete</a></li> </ul> </div> </div> <script th:inline="javascript"> /*<![CDATA[*/ function onReadClick() { var id = $('#myval').value; /*[+ var myUrl = [[@{/read}]] + id; +]*/ window.location.href = myUrl; }); /*]]>*/ </script> 将完成这项工作。关于Python 2和3中输入差异的This question可能会对您有所帮助。

此外,我认为参数raw_input不是必需的。仅s不会改变s.lower()的价值。

s