+ 1
I want to print the items in a single line like this: 10 20 30 40 . Not on separate lines, but it prints on separate lines. Why?
qwerty = [10, 20, 30, 40] for w in qwerty: print(str (w) + " ")
13 odpowiedzi
+ 3
qwerty = [10, 20, 30, 40]
for w in qwerty:
print (str (w) , sep=" ,",end = ".")
# Alvin✓ sep attribute for separating values
#end attribute used to set end point as shown
+ 2
Jayakrishna🇮🇳 please do well to explain the last line
+ 2
default value is end="\n" so override end="" . It just cause to put "" instead of \n
check this in playground for print syntax and explanation of more attributes. hope it clears
help(print) #Alvin✓
+ 2
But how do I put a full stop at the end?
After putting commas in between the items
qwerty = [10, 20, 30, 40]
for w in qwerty:
print (str (w) + " ", end = ", .")
+ 2
Jayakrishna🇮🇳 Thanks a lot.
Are the sep and end attributes taught in the python core course here in sololearn?
+ 2
Am not sure, is it there or not. But you can get from documention or in interpreter by
help(print)
+ 2
Alvin✓ Note: sep and end aren't attributes, they're named parameters
+ 1
qwerty = [10, 20, 30, 40]
for w in qwerty:
print(str (w) + " ",end="")
#Note : default is end="\n" so override end=""
+ 1
qwerty = [10, 20, 30, 40]
need = ""
for i in range(len(qwerty)):
need = need + str(qwerty[i]) + " "
print (need)
+ 1
Another way:
qwerty = [10, 20, 30, 40]
str_qwerty = srt(qwerty)
str_qwerty.replace("[", "")
str_qwerty.replace("]", "")
print (str_qwerty)
+ 1
Alvin✓ They aren't keywords. Keywords make up a separate statement, not a part of a function call. It's just that two of the function's parameters are named and can be passed using their names, end and sep (which eliminates the burden of remembering the order of giving the args)
0
Hey Jayakrishna🇮🇳 I've found a solution to put a full stop at the end 🥳😃. Try this 👇🏻
qwerty = [10, 20, 30, 40]
for x in qwerty:
print (str (x), end = ", ")
if x == qwerty[-1]:
print (str (qwerty[-1] + ".")