python - 如何要求一个字符串,然后要求一个字符串的位置,然后删除字母并打印没有字母的单词
问题描述
Python
我想创建一个程序,要求用户输入一个字符串,然后要求用户选择要删除的字符串的位置,然后打印没有他选择要删除的位置的字母的字符串。我正在努力寻找正确的方法来做到这一点。
x = input ('Enter a String: ')
sum = 0
if type(x) != str:
print ('Empty Input')
else:
y = input ('Enter the position of the string to be removed: ')
for i in range x(start, end):
print ('New string is: ', x - i)
解决方案
本质上,您如何做到这一点只是使用 .split() 方法通过字符串字母的索引将其拆分,然后使用 join() 方法将其连接起来
x = input ('Enter a String: ')
sum = 0
if type(x) != str:
print ('Empty Input')
else:
y = int(input('Enter the position of the string to be removed: '))
x = ''.join([''.join(x[:y]), ''.join(x[y+1:])])
print(x)
推荐阅读
- javascript - 从要删除的 li 中找到特定的锚链接
- c# - Linq C# 中的空值异常处理
- python-3.x - matplotlib 3d 绘图问题
- kotlin - 如何在 Kotlin 中将布尔运算符作为参数移交?
- python - 索引对索引组件无效。pyomo中具有双索引的参数
- python - 如何将组合框绑定到单选按钮
- react-native - 是否有可能动态添加应用程序图标以响应本机应用程序
- javascript - Cordova Media 插件暂停
- android - 使用改造调用服务时出错 Expected BEGIN_ARRAY 但在第 1 行第 1 列路径为 STRING $
- javascript - 有角度的两个验证同时触发