99问答网
所有问题
python 中如何提取字母?
比如
a = 'hello123 world@#$!'
如何得到a1 = ‘helloworld’
?
举报该问题
其他回答
第1个回答 2013-11-06
>>> a = 'hello123 world@#$!'
>>> a1=''.join([x for x in a if x.isalpha()])
>>> a1
'helloworld'
简略形式:
>>> a1=''.join(x for x in a if x.isalpha())
>>> a1
'helloworld'本回答被提问者采纳
第2个回答 2013-11-06
我只想到一个一个的判断,如下。
a='hello123 world@#$!'
a1=''
for c in a:
if c.isalpha():
a1=a1+c
print(a1)
第3个回答 2013-11-06
or usage regex
>>> import re
>>> a = 'hello123 world@#$!'
>>> patt = re.compile(r"[\W\d]+")
>>> patt.sub('', a)
'helloworld'
>>>
第4个回答 2013-11-06
import re
a = 'hello123 wor_ld@#$!'
s = re.sub('[^a-zA-Z]', '', a)
print(s)
第5个回答 2015-09-14
filter(str.isalpha, '213fdgfg45v5eg')
相似回答
python
输入一个英文句子+输出单词个数量,
提取
首
字母?
答:
提取
首
字母
first_letters = [word[0] for word in words]print("首字母:", first_letters)
python
中如何提取字母?
答:
>>> a = 'hello123 world@#$!'>>> a1=''.join([x for x in a if x.isalpha()])>>> a1'helloworld' 简略形式:>>> a1=''.join(x for x in a if x.isalpha())>>> a1'helloworld'
python
编写程序 对用户输入的英文字符串中出现的英文
字母
进行
提取
...
答:
a.输出为小写
字母
:--- b.输出为大写字母:--- c.其它例子:写在最后: 上面给
的
代码差别就在于upper()函数及lower()函数, 而输入没啥限制, 光字母,或汉字字母混着等都没问题. 但代码写的不是太好,只是将基本的逻辑实现了 希望可以帮到题主, 欢迎追问 ...
python中如何提取
单词的首
字母
答:
a='123123' #单个字符串print a[0]a='asd asd 12 asd 232' #多个字符串print [i[0] for i in a.split(' ')] #根据实际情况分割 是否剔除不是单词的字符串 如12 那就自己加判断
PYTHON
提取
字符串中10个不同
字母
视频时间 0:10
python
自动选择一个
字母
答:
尽管如果您只选择一个不会造成任何变化
的字母
,而且,您可能需要5个唯一的字母-OP没有指定,并且random.choice和random.randint都返回一个值。
Python
是一种跨平台的计算机程序设计语言是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言最初被设计用于编写自动化脚本(shell),随着版本的不断...
python
能输出数字不能输出
字母?
答:
Python
可以输出
字母
,只需要将字母放在字符串中即可。例如:
python
print("Hello World")这会输出字符串 "Hello World",其中包含字母。如果要输出数字,也可以直接将数字放在 print 函数中:python print(123)这会输出数字 123。如果要输出某个变量的值,也可以使用 print 函数,例如:python x = 456...
python
编写一段代码,要求用户从键盘输入一字符串,程序负责
提取
出其中...
答:
1、创建
python
文件,testregexp.py文件;2、编写代码
提取
字符串中
的
数字;string="12abc34wf5s!@#6af7"list_str1=re.findall(r"\d*",string)list_num=''.join(list_str1)print(list_num)3、编写代码,提取字符串中的英文
字母
;提取字符 list_str2=re.findall("[a-z]*",string)list_...
求
python
大大,
如何取
一个句子里所有单词的最后一个
字母?
答:
a = 'My name is Max.'print ''.join(each[-1] for each in a.strip('.').split())
大家正在搜
python从字符串中提取字母
python提取列表中的字母
python提取字母数字
python提取首字母
python提取每个单词首字母
python字符串字母怎么取出
python把字符串中字母删除
python字符串中字母个数
python字符串保留字母和数字
相关问题
python怎么提取字符串里的字母?
Python如何提取字符串中的字母?
python怎么提取字符串里的字母?
Python如何提取字符串中的字母?正则应该怎么写?
Python在字符串里提取字母正则应该怎么写?
python正则怎样匹配出字符串中的字母?
python如何自动生成单个随机字母(a-z)。
如何使用python的list中提取字母,然后自己输入lis...