擅长:python、mysql、java
<p>另一种简化代码的方法是使用<a href="https://docs.python.org/3/library/stdtypes.html#str.lower" rel="nofollow noreferrer">^{<cd1>}</a>将字符串转换为小写,并使用字符串<a href="https://docs.python.org/3/tutorial/introduction.html#strings" rel="nofollow noreferrer">slice</a>检查不带第一个字符的字符串:</p>
<pre><code>rare_letter = 'q'
user_surname = input("What is your surname? ").lower()
if user_surname[0] == rare_letter:
print("You have an extremly rare surname!")
elif rare_letter in user_surname[1:]:
print("You have a rare surname!")
else:
print("No Qs here.")
</code></pre>
<p>试试看<a href="https://repl.it/Jyex/1" rel="nofollow noreferrer">here!</a></p>