/    Sign up×
Community /Pin to ProfileBookmark

How do you add spaces before and after a word in Python?

Just print or return with actual space characters. Hopefully you also realise there are different forms of “spaces” in programming.

Simple examples…

a = “TheWord”

# FOR NORMAL SPACE CHARACTERS.

print(” ” + a + ” “)

# FOR TABS…

print(“tTheWordt”) #Or…
print(“t” + a + “t”)

# FOR NEW LINES…

print(“nTheWordn”) #Or…
print(“n” + a + “n”)

to post a comment

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 13.2022 — @SubhanUllah#1646985

Why are you using this site to write blog articles? It's a place to ask questions: not to answer questions nobody is asking.
Copy linkTweet thisAlerts:
@marionlankfordSep 17.2022 — Hey

Using loop + join()

This is one of the ways in which this task can be performed. In this, we perform the task of iterating all the stings and then all the characters before adding space using loop in brute force manner. The isupper() is used to check for capital character.
×

Success!

Help @SubhanUllah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...