【问题标题】:1. Delete all the lowercase alphabets from the string. input="amiT123" output="T123"1. 从字符串中删除所有小写字母。输入="amiT123" 输出="T123"
【发布时间】:2019-10-04 18:12:18
【问题描述】:
  1. 从字符串中删除所有小写字母。
input="amiT123"
output="T123"

a="amiT123"
print(input.replace(input.lower,""))

【问题讨论】:

标签: python-3.x


【解决方案1】:

使用正则表达式很容易解决这个问题

import re
input = "amiT123"
result = re.sub(r"[a-z]","",input)
print(result)

有关正则表达式的更多信息:wikibooks.org

【讨论】:

  • 如何将它们分成大写、小写、整数?输出=[ami][T][123]
  • 使用 re.findall(r"([az]|[AZ][0-9]",input),这应该找到小写组、大写组和数字组并返回您的结果列表以获取更多信息:docs.python.org/3/library/re.html#re.findall 也可以使用 re.split 函数,尚未测试。
猜你喜欢
  • 2013-03-12
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 2014-04-26
  • 1970-01-01
  • 2023-02-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多