Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Code works but why? - Python 3.10 - string manipulation
Post Body

The following code works but I don't understand why? I would think [:2] would give me the first three letters but in fact gives me two. I have included the instructions for reference.

Write a function that stutters a word as if someone is struggling to read it. The first two letters are repeated twice with an ellipsis ... and space after each, and then the word is pronounced with a question mark ?.

word = input("Enter a word.")

def stutter(word):

sword = word

print (sword[:2],"...",sword[:2],"...",sword,"?")

stutter(word)

Here is the output.

Enter a word.Function

Fu ... Fu ... Function ?

Assuming the index starts at zero shouldn't [:1] give me the first two letters?

Thanks

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
122,699
Link Karma
3,525
Comment Karma
118,576
Profile updated: 7 hours ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago