Skip to content

49. What is the output of following code in Python?

name=’John Smith’ >>>print name[:5] + name[5:] Ans: Output of this will be John Smith This is an example of Slicing. Since we are slicing at the same index, the th th first name[:5] gives the substring name upto 5 location excluding 5 th location. The name[5:] gives the rest of the substring of name from the 5 location. So we get the full name as output.