স্ট্রিংয়ের শব্দের পরে আমার সাদা স্থানগুলি সরিয়ে ফেলতে হবে। কোডের এক লাইনে এটি করা যায়?
উদাহরণ:
string = " xyz "
desired result : " xyz"
স্ট্রিংয়ের শব্দের পরে আমার সাদা স্থানগুলি সরিয়ে ফেলতে হবে। কোডের এক লাইনে এটি করা যায়?
উদাহরণ:
string = " xyz "
desired result : " xyz"
উত্তর:
>>> " xyz ".rstrip()
' xyz'
সম্পর্কে আরো rstripমধ্যে ডক্স
words = " first second "
# remove end spaces
def remove_first_spaces(string):
return "".join(string.rstrip())
# remove first and end spaces
def remove_first_end_spaces(string):
return "".join(string.rstrip().lstrip())
# remove all spaces
def remove_all_spaces(string):
return "".join(string.split())
print(words)
print(remove_first_spaces(words))
print(remove_first_end_spaces(words))
print(remove_all_spaces(words))
আমি আশা করি এই সহায়ক।