Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my understanding words[len(words) - 3: ] is the total length of the string minus any character from 3 to the end, which is from 3 to blank space. Therefore the letters1 should equal to " Pr", but why the Python output shows "ng"


VB
words = " Prince Charming "

letters1 = words[len(words) - 3: ]


print(letters1)
Posted
Updated 2-Aug-17 17:21pm

1 solution

letters1 = words[len(words) - 3: ]

This means all characters from 14th character
answer -
ng

If you want all characters before 14th shift colon to left side
<pre>letters1 = words[:len(words) - 3 ]

answer -
Prince Charmi

Or if you want just first 3 characters
letters1 = words[:3 ]

answer
Pr
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900