M
M
Marina18022021-10-12 22:32:23
Python
Marina1802, 2021-10-12 22:32:23

How to replace all letters 'k' with 'c' and remove numbers from a string?

We need to replace all letters 'k' with 'c' and remove numbers from the string 'Kharchenko Maryna, 1KL, 22'.

name = input('Put your surname, name, group and number of Lab:')
a = name 
print(a)

#Зад. 2а - вставить строку "no" между 11 і 12 символом
a1 = print(a[:12], 'no', a[12:], sep='')

#Зад. 2б - заменить все буквы «k» на «c»


#Зад. 2в - убрать все цифры со строки
for i in a:
    if i not in {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}:
        print(a)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-10-12
@Marina1802

''.join(filter(lambda x:not x.isdigit(), 'Kharchenko Maryna, 1KL, 22'.replace('k', 'c')))
# 'Kharchenco Maryna, KL, '

S
ScriptKiddo, 2021-10-12
@ScriptKiddo

You need to replace all the letters 'k' with 'c'

'abc'.replace('a', 'b')
# 'bbc'

remove numbers from string 'Kharchenko Maryna, 1KL, 22'
test = 'Hello123'

test = ''.join(x for x in test if not x.isdigit())
# 'Hello'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question