问题描述
我有以下组合变音符号
[ọ́,ọ̀,ẹ̀,ẹ́]
。在通过像
这样的字符串中的字符串索引访问它们时,我希望将它们保留为一个字符"ọ̀rẹ̀"
例如当前的拆分是:
class Employee:
def __init__(self,name,salary,lang,post):
self.name = str(name)
self.salary = int(salary)
self.lang = str(lang)
self.post = str(post)
def print_info(self): # Not named get; get implies you *return* the info; use snake_case over camelCase per Python's PEP8 style guide
print(f"Name of the person is {self.name}")
print(f"Language of the person is {self.lang}")
print(f"Post of the person is {self.post}")
def print_salary(self): # See above for name change reason
print(f"The salary for {self.name} is {self.salary}")
def give_raise(self,amount_raised): # Much more explanatory name than "inc"
self.salary += int(amount_raised) # Avoid repeating self.salary using +=
print(f"Incremented salary is {self.salary}") # disagree with printing when this happens,but you do you I guess
def cut_pay(self,amount_lost): # Again,explanatory names are good (makes it clear value expected to be positive
self.salary -= int(dec) # Avoid repeating self.salary using -=
print(f"Decremented salary is {self.salary}")
# If not for the prints in each,I'd just implement this as:
return self.give_raise(-amount_lost)
# to reduce code duplication,or replace both functions with a single
# function,"adjust_salary" that takes a positive value for raises,# negative for cuts,but leaving it separate due to prints conTradicting
如何使 s[0] 和 s[1] 成为一个字符而不是原始字符串中的两个字符?
任何想法如何在 python 中完成这项工作?
解决方法
如果您想从列表字符创建字符串,只需使用 join
方法
x = ['ọ́','ọ̀','ẹ̀','ẹ́']
print("".join(x))