Print raw string from variable? (not getting the answers)

后端 未结 11 971
后悔当初
后悔当初 2020-12-04 10:14

I\'m trying to find a way to print a string in raw form from a variable. For instance, if I add an environment variable to Windows for a path, which might look like \'

11条回答
  •  天命终不由人
    2020-12-04 11:08

    try this. Based on what type of output you want. sometime you may not need single quote around printed string.

    test = "qweqwe\n1212as\t121\\2asas"
    print(repr(test)) # output: 'qweqwe\n1212as\t121\\2asas'
    print( repr(test).strip("'"))  # output: qweqwe\n1212as\t121\\2asas
    

提交回复
热议问题