Here the sequence \n inserts the literal characters \ and n so the Python interpreter does not get a newline.
However if your shell is capable of inserting control characters you can insert a newline. For example in bash:
$ python3 -c $'print(1)\nprint(2)'
1
2
Note that to give an actual backslash to Python you have to double it inside $'...':
$ python3 -c $'print(r"a\\b")'
a\b
I have no idea what is “next shell” but in bash and probably any POSIX-compliant shell you just need to use double quotes to keep the whitespace characters:
$ code=$(cat test1.py) # Assignment is an exception. Here double quotes are not necessary.
$ python3 -c "$code"
first line
second line