如何在python 3.7中转义逗号和斜杠

时间:2018-11-05 14:13:24

标签: python string python-3.x escaping comma

我试图在python中转义逗号和斜杠,这是我的代码。

    string user_Email = ("Hi {},

    Please see below for {} initial login details

Computer Login (Active Directory)
Login: {}
Password: {}

Google
https://gmail.com
Email: {}
Password: {}
2FA: Once logged in, please enable 2-step verification https://www.google.com/landing/2step/, download and use Google Authenticator app on your phone. If you don't setup 2-step verification you will get locked out of your Google account.

我该怎么做?

1 个答案:

答案 0 :(得分:1)

多行字符串文字应使用三引号。 """'''

如果要将大块文本分配给一个变量,它将是这样的:

user_Email = """Hi {},

Please see below for {} initial login details

Computer Login (Active Directory)
Login: {}
Password: {}

Google
https://gmail.com
Email: {}
Password: {}
2FA: Once logged in, please enable 2-step verification https://www.google.com/landing/2step/, download and use Google Authenticator app on your phone. If you don't setup 2-step verification you will get locked out of your Google account
"""

如果您实际上需要转义逗号或斜杠,则必须指定要尝试转义的内容。