Just append it before the name and print: print("/"+a)
How to add a slash to an input
質問
How do you add a slash(/) in front of an input e.g:
a=input('What is your name')
print(a)
it should print with a slash before the name?
解決
他のヒント
or just print a dash:
print('-{}'.format(a))
or just print a dash:
print('-%s' % a)
or just print a dash (credits to @icodez):
print('-', a, sep='')
or just print dash (credits to @xndrme):
print('-'+a)
and the same works with a slash:
print('/{}'.format(a))
print('/%s' % a)
print('/', a, sep='')
print('/'+a)
;-)
Just print a dash* and set the sep
parameter of print
to ''
(to remove the space after it)**:
a = input('What is your name')
print('-', a, sep='')
Below is a demonstration:
>>> a = input('What is your name')
What is your namebob
>>> print('-', a, sep='')
-bob
>>>
*Note: I used a dash (-
) in my demonstrations because that is what you said. However, the same principle applies to a forwardslash (/
).
**Note: I also assumed that you are on Python 3.x. If you are on version 2.x though, then you can do this:
>>> a = raw_input('What is your name')
What is your namebob
>>> print '-'+a
-bob
>>>
所属していません StackOverflow