cooldog cooldog - 5 months ago 9
Python Question

Python insert tab in string

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

Answer

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.

Comments