+ 1
Pig latin, need explanation!
Please can anybody explain the for loop body, I have understand that how did the slicing work, but at hear I'm confused! n = input().split() for n in n: print((n[1:]+n[0:1]+'ay'),end =' ')
4 Answers
0
Second line is pointless, split returns a list already. As for the loop, after splitting the sentence in words, it's taking the first letter of the word and putting it at the end using slicing and it also adds ay at the end, to avoid newline print is also passed another parameter "end" which by default is \n, it's changed to be a whitespace so every word gets print out with spaces between them, avoiding the need of "join"
0
Bagon ok i'll remove that.
And Thanks for explanation dear.
I was confused on n[0:1] in for loop body,because when i try [0:1] this in a string list without for loop it occurs error.
And now i've understood that without iterating a list with loop we can't slice it.
Thanks again.
0
Jahir Raihan Joy you're welcome, BTW to simplify it you can remove that 0
n[0:1] is the same as n[:1]
0
Bagon Thank you so much brother.