简体   繁体   中英

I have a variable as a tuple how can I return it as a string

I want to get the middle letter of a word, but I want the result to print as a string. How can I do so?

def get_middle(word):
    a = int(len(word))
    b = int(len(word)/2) 
    c = int(len(word)/2 - 1)
    d = int(len(word)/2 - 0,5)
    if a%2==0:
      print(str(word[b] + word[c]))


    elif a%2==1:
        print(str(word[d]))

    else:
        print("That's not a sring!")
def get_middle(word):
    if len(word)%2 == 1:
        return word[:int((len(word)-1)/2)]+word[int((len(word)-1)/2)+1:]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM