How to move the first letter of a word to the end

后端 未结 3 1680
梦如初夏
梦如初夏 2020-12-06 16:01

I need to remove the first letter of a word and move it to the end, for example:

word = \'whatever\'
# I want to convert it to \'hateverw\'

相关标签:
3条回答
  • 2020-12-06 16:17

    Here is what I did:

    wrd = input("Give me a word: ")
    
    pig = wrd[1:] + wrd[0] + "ay"
    
    print(wrd, "in Pig Latin it is:", pig.lower())
    
    0 讨论(0)
  • 2020-12-06 16:24

    You could use:

    word[1:]+word[0]
    
    0 讨论(0)
  • 2020-12-06 16:32

    CODE :

    word=input()
    print(word[1:]+word[0])
    

    OUTPUT :

    >>> oHell
    >>> Hello
    

    The code (word [1:0]) prints from the second character till the last.

    If you want to write a code to print the first character then write the code as:

    a="AbC"
    print(a[0])
    

    OUTPUT :

    >>> A
    

    Because the index of the string always starts from 0 and not 1.

    0 讨论(0)
提交回复
热议问题