0

My code:

name=input('What is your name?')
print('So you call yourself \'',name,"' huh?")

My output

What is your name?lll
So you call yourself ' lll ' huh?

Need to get rid of the space between lll and apostrophes

M_S_N
  • 2,764
  • 1
  • 17
  • 38

3 Answers3

1

f-Strings are new and Improved Way to Format Strings in Python and you can use these to get your desired output like this:

print(f'So you call yourself "{name}" huh?')
print(f"So you call yourself '{name}' huh?")

Output:

So you call yourself "Raja Norhuda Adnan" huh?
So you call yourself 'Raja Norhuda Adnan' huh?
M_S_N
  • 2,764
  • 1
  • 17
  • 38
  • It does not answer the question. The question is about having quotes around the{name} part. – RvdK Jan 24 '20 at 08:41
1

There are many ways to make this:

First one using % operator

name = "Alex"

print('So you call yourself "%s" huh?' % name)

Second using format

name = "Alex"

print('So you call yourself "{}" huh?'.format(name))
print('So you call yourself "{name}" huh?'.format(name=name))

Using f-string (works only in Python 3.6)

name = "Alex"

print(f'So you call yourself "{name}" huh?')

In all 3 cases result will be the same.

You can even go further and do something like this

print('So you call yourself "#name#" huh?'.replace('#name#', name))

If you worried about performance you can check this question

alex2007v
  • 1,230
  • 8
  • 12
0

A trick is to mix quotes:

name = 'foo'
print(f"So you call yourself '{name}' huh?")

" around the complete string

' around the item

RvdK
  • 19,580
  • 4
  • 64
  • 107