3

I just began learning Python. I'm not sure how to insert tab in string. For instance, how can i insert tab to the right of "World" in the strings below:

example = '    Hello World'

Everytime I use Tab after "World" a drop down menu appears, how can I avoid that? thanks! I tried using \t, but then example.lstrip() gives the result of Hello World\t, instead of Hello World

Thanks for the answers. I used example = ' Hello World\t', it works. print(example.lstrip()) gives the result: Hello World , without \t

3
  • 1
    lstrip strips the left only... strip strips both sides. Commented Jun 30, 2016 at 19:53
  • Just use example[:-1] to get rid of final tab character. Commented Jun 30, 2016 at 19:53
  • your editor is creating the drop down. Are you using IDLE? Don't. str.lstrip only strips whitespace off the left side, leaving the trailing \t intact. Commented Jun 30, 2016 at 19:53

1 Answer 1

11

The dropdown error is because of the editor you are using. Just try using plain notepad++. It's working! I tried.

print "Hello World\t",
print "hi"

Just to make sure that there is tab after the first print, print one more statement. you will come to visual it. Make sure to use comma ',' after print to stay in the same line if you are using python 2.7. Else use end="" for python 3+ to stay in the same line.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.