+ 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 ?
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)
+ 1
" \n " between print function.
after the character where you want new line.
(similarly "\t" is used for a "tab" )
+ 1
can't we do it like c
for example,
printf("%d \n\n %d", x,y);
+ 1
yes if %d doesn't works
use %i for int
and %s for string
but i prefer this:-
print("\n" , a, "\n", b)
+ 1
after second "\n" use space
like this
"\n " or "\n\t"
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 ?
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
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
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) .