如果您想要的字符串是固定长度的,您可以将第一个字符作为新字符串。#This is the full string with gibberishfullString = 'StackOverflow1235125'#We'd like to get StackOverflowgetString = 'StackOverflow'#We need the lengthgetStringLength = getString.__len__() #This returns 13 because StackOverflow is 13 chars.returnString = fullString[:getStringLength] #This trims the fullString, only leaving the first 13 characters.print(returnString)输出是StackOverflow