0

What's happening here?

In [1]: q = 'deadbeef\t1.2.3.4\t2019-07-04\r",2019-07-02\r\n' 
   ...:                                                                                                                                                                                                                                  

In [2]: print(q)                                                                                                                                                                                                                         
",2019-07-02    1.2.3.4 2019-07-04


In [3]: 

Why is print inverting the order of the substrings? I've tested it on python 2.7, 3.6, 3.7

user37203
  • 676
  • 5
  • 21
  • 4
    There’s an `\r`. `\r` (without `\n`) goes back to the start of the line and writes over it. – Ry- Sep 28 '19 at 08:20
  • At first i was like, how can someone break python `:0`. After reading the explaination, i'm like `__|_` . – taurus05 Sep 28 '19 at 08:23
  • Use raw string to print it without any error. `q = r'deadbeef\t1.2.3.4\t2019-07-04\r",2019-07-02\r\n'`. Or, use `repr(q)` instead. – CypherX Sep 28 '19 at 08:31

0 Answers0