2012-10-16 3 views
-2

Je dois enlever la première lettre d'un mot et le déplacer vers la fin, par exemple:Comment déplacer la première lettre d'un mot à la fin

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

Jusqu'à présent, je l'ai essayé ceci:

word[1:] # hatever 

Mais comment dois-je déplacer la première lettre à la fin?

+3

http://www.whathaveyoutried.com? –

Répondre

8

Vous pouvez utiliser:

word[1:]+word[0] 
+0

Comment s'appelle-t-on lorsque vous utilisez varaiblename [1:]? Je voudrais rechercher plus à ce sujet pour trouver plus d'informations de syntaxe. – Crutchcorn

+1

Ceci est appelé Python [notation tranche] (http://stackoverflow.com/q/509211/190597), ou juste [slicing] (https://docs.python.org/2/tutorial/introduction.html#strings). – unutbu

0

Voici ce que je faisais:

wrd = input("Give me a word: ") 

pig = wrd[1:] + wrd[0] + "ay" 

print(wrd, "in Pig Latin it is:", pig.lower()) 
Questions connexes