How do I insert a line gap between the two outputs in the below code in python ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do I insert a line gap between the two outputs in the below code in python ?

x = 2 print(x) y = 3 print(y) I want to print these with a two line gap in between x and y, how to do that ?

22nd Mar 2020, 6:20 AM
Sk. Ahmed Razha Khan
Sk. Ahmed Razha Khan - avatar
9 Answers
+ 1
Use escape sequences Different escape sequences are: /n for new line /t for tab x=2 print(x) print("/n/n") y=3 print(y)
22nd Mar 2020, 6:24 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 1
" \n " between print function. after the character where you want new line. (similarly "\t" is used for a "tab" )
22nd Mar 2020, 6:28 AM
Noman S. Shiekh
Noman S. Shiekh - avatar
+ 1
can't we do it like c for example, printf("%d \n\n %d", x,y);
22nd Mar 2020, 6:36 AM
Sk. Ahmed Razha Khan
Sk. Ahmed Razha Khan - avatar
+ 1
yes if %d doesn't works use %i for int and %s for string but i prefer this:- print("\n" , a, "\n", b)
22nd Mar 2020, 6:37 AM
Noman S. Shiekh
Noman S. Shiekh - avatar
+ 1
after second "\n" use space like this "\n " or "\n\t"
22nd Mar 2020, 6:47 AM
Noman S. Shiekh
Noman S. Shiekh - avatar
0
and norman, in print("\n",a,"\n",b) , what to do if I need to print like this a b I mean to insert spaces in the new line ?
22nd Mar 2020, 6:45 AM
Sk. Ahmed Razha Khan
Sk. Ahmed Razha Khan - avatar
0
x=4 y=5 print("\n",x,"\n",y) if I run this, I'm getting an output of " 4 5" x=4 y=5 print(x,"\n\n",y) for this im getting "4 5" how is this happening ? I'm getting a space before 5 in the second case
22nd Mar 2020, 6:53 AM
Sk. Ahmed Razha Khan
Sk. Ahmed Razha Khan - avatar
0
Nothing much u just need to insert these characters inside the print for Newline character: \n Tab space: \t example: print("\nhi\ngud\tmrng\n") Output: hi gud mrng
22nd Mar 2020, 7:57 AM
Anuhya Anu
Anuhya Anu - avatar
0
I just remembered one more technique. print("a"*2) with this "a" (must be a string) will be printed "2" times by changing 2to any no. u can print it that much time. and same for *new lines* . if u want more than one new lines just multiply print("\n" * number) by that number(no. of newlines) .
25th Mar 2020, 9:35 AM
Noman S. Shiekh
Noman S. Shiekh - avatar