Mutations | HackerRank
Understand immutable vs mutable by making changes to a given string.
www.hackerrank.com
Goal
Read a given string, change the character at a given index and then print the modified string.
Solution
We need to understand slicing and indexing Strings in Python. You can check this link.
#Mutations
def mutate_string(string, position, character):
new_string = string[:position] + character + string[position+1:]
return new_string
if __name__ == '__main__':
s = input()
i, c = input().split()
s_new = mutate_string(s, int(i), c)
print(s_new)
'software Engineering > (Python)HackerRank' 카테고리의 다른 글
[Python] HackerRank - String Validators (0) | 2023.02.16 |
---|---|
[Python] HackerRank - Find a string (0) | 2023.02.15 |
[Python] HackerRank - What's Your Name? (0) | 2023.02.11 |
[Python] HackerRank - String Split and Join (0) | 2023.02.07 |
[Python] HackerRank - sWAP cASE (0) | 2023.02.03 |