Not able to print statements with 'Apostrophe' in it in Python. Invalid syntax error

前端 未结 5 1965
眼角桃花
眼角桃花 2020-12-03 17:50

Eg.

when iam trying to write something like below which uses an apostrophe in the sentence,

print(\'\'I am jack\'s raging bile duct\'\')
相关标签:
5条回答
  • 2020-12-03 17:53

    don't use double ', use "

    print("'I am jack's raging bile duct'") should work

    0 讨论(0)
  • 2020-12-03 18:03

    There are 2 ways:

    print('I am jack\'s raging bile duct')
    

    or:

    print("I am jack's raging bile duct")
    
    0 讨论(0)
  • 2020-12-03 18:06

    '' is not a double quote.
    You want ".

    0 讨论(0)
  • 2020-12-03 18:07

    You can use both " and ' to write a string in Python, a double ' ('') will be invalid.

    If you use ", the syntax for your case would be

    print("I am jack's raging bile duct")
    

    But if you use ', you may need to escape the apostrophe as follows:

    print('I am jack\'s raging bile duct')
    

    In general, if you use ", and your string has also ", you will need to escape every " in your string, except the one that closes, same happens with '.

    0 讨论(0)
  • 2020-12-03 18:11

    Use of double quotes will do the trick. print("I am jack's raging bile duct") I tried it and works good. Happy coding!

    0 讨论(0)
提交回复
热议问题