Home > front end >  End of statement expected while using Dot Format
End of statement expected while using Dot Format

Time:04-27

I need to print the following of code :

print('hello "my friend '{}' "'.format(name))

such that the output is:

'hello "my friend 'ABCD' " '

But I get the error: End of Statement expected

What is the correct syntax?

CodePudding user response:

You need to escape quotes if you want to use them in a string:

print('hello "my friend \'{}\'"'.format(name))

CodePudding user response:

Try this,

print("""hello "my friend '{}' " """.format(name))
  • Related