![](/img/trans.png)
[英]Python - Checking an input for numbers, uppercase, lowercase letters and special characters
[英]Uppercase Function with Special Characters Python
我正在編寫一個非常簡單的程序供個人使用,以便可以將小寫字符串轉換為大寫。 但是,當我有特殊字符(例如括號“()”)時,我遇到了問題。是否可以忽略所有特殊字符,但仍然打印它們? 例如,如果我傳入(你好),我想收到(HELLO)。 我的代碼是:
import sys, re
upper_case = []
lower_case = sys.argv[1:]
for word in lower_case:
upper_case.append(word.upper())
for item in upper_case:
print item,
您可能考慮讓程序提示您輸入字符串。 這樣可以避免涉及您的操作系統的“特殊字符”出現任何問題:
#! python3
while True:
lcstring = input("\nText?> ")
print("\n",lcstring.upper())
我添加了一些額外的換行符,以使其更易於使用鼠標復制/粘貼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.