This question already has answers here:
How can I print multiple things on the same line, one at a time?
(18 answers)
Closed 3 years ago.
I want to know how to print output in a single line
I want to print it like: 1234
instead of
1
2
3
4
Code:
# n = (get in from user)
i=1
while (i<=n):
print (i,)
i +=1
This may help :
For Python 3:
print(i,end='')
For Python 2:
print(i),
Related
This question already has answers here:
Why is "None" printed after my function's output?
(7 answers)
Why is this printing 'None' in the output? [duplicate]
(2 answers)
Closed 1 year ago.
This is my code, when I run it gives me the right answer but also it gives me 'None':
My Code:
def art() :
a = input('enter a values')
b = eval(a)
print(b)
print(art())
Output:
enter a values3 + 4
7
None
Does anyone know why is that and how to remove it? Thank you.
This question already has answers here:
Why are str.count('') and len(str) giving different output?
(3 answers)
Closed 4 years ago.
I was going through something when i came across this...
a = 'hello'
print(a.count('l'))
print(a.count(''))
Output is :
2
6
Can anyone explain why the second output is 6 ?
count here returns the number of occurences of your substring, here a '' string.
There are indeed six '' in hello, between each char:
print(''.count('')) # >> 1
# You could symbolize it like that:
print('a'.count('')) # >> 2
# is equivalent to:
print('|a|'.count('|')) # >> 2
This question already has answers here:
How to print without a newline or space
(26 answers)
Closed 5 years ago.
for example, I want to print
01234567
so I know I need to write
for i in range(8)
print(i),
and it will print 0 1 2 3 4 5 6 7
instead of change the line for every number
but I want it whithout spaces
You can use some Python 3 features in Python 2:
from __future__ import print_function
for i in range(8):
print(i, end='')
Output:
01234567
This question already has answers here:
Pythonic way to check if a list is sorted or not
(27 answers)
Closed 6 years ago.
I have this list from user input:
sun=[8,8,7,7,4,6,4,5,]
>>> sun.index(8)
0
>>> sun.index(7)
2
>>> sun.index(4)
4
Would like to write a program to print "Impossible", because 4,5,6 are not in correct order in the list.
print "Impossible" * (sun != sorted(sun))
This question already has answers here:
How can I print multiple things on the same line, one at a time?
(18 answers)
Print in one line dynamically [duplicate]
(22 answers)
Closed 6 years ago.
I'm searching for printing this :
random_numbers = [1, 5, 25, 4, 60]
print("Numbers are : ")
for elem in random_numbers :
print(elem, end=' ')
and the result have to be like this :
Numbers are : 1 5 25 4 60
So on the same line, with space and no quote. I searched for this on several forums and try to put in a function and call it right after printing "Numbers are : " but nothing worked, please help!