Skip to content
Sign upLog in
← Back to Community

Python Tutorial on Printing a list without the quotation marks [" "]

Profile icon

Python Tutorial on Printing a list without the quotation marks " "

Let me explain myself a little further.
Since when you print a list, this is what it should print out.


sentence = ["P", "y", "t", "h", "o", "n", " ", "i", "s", " ", "a", "w", "e", "s", "o", "m", "e", "."] print(sentence)


["P", "y", "t", "h", "o", "n", " ", "i", "s", " ", "a", "w", "e", "s", "o", "m", "e", "."]

It literally printed out the list. How do you print out Python is awesome without doing print("Python is awesome") and you need to create a list?

This is what tutorials are for >:).


Only need to import sys

import sys # for printing stuff in one line(will talk about this further later on)

Create a list

You have to create a list of the things you want to print.
In this case, it's Python is awesome.

sentence = ["P", "y", "t", "h", "o", "n", " ", "i", "s", " ", "a", "w", "e", "s", "o", "m", "e", "."] # you don't have to use the variable "sentence"

Actual logic/code Step 1

Now we got everything set up, time for the logic!
In order to print everything, we need to print each and individual index of the list like:

print(sentence[0]) print(sentence[1]) # etc.

But that's wayyyyyy to slow. And coding is about efficient code. The less the better (but has to be the same output).

Now you think about it, we need to use a for loop. But how many times? We can't just count how many indexes there are, so we do this cool function, len(sentence) will calculate how many indexes are in the list.

So first steps is:

for i in range(len(sentence)): # don't need to use i # step 2

Step 2

What is in the for loop? Before that, we have to assign a variable a value because in the for loop, we should keep adding on to the variable the number of how many indexes. (If you are confused, I failed.😞😭) But let's see the actual code.

x = 0 for i in range(len(sentence)): print(sentence[0])

Now we got that, we need to keep adding on to x:

x = 0 for i in range(len(sentence)): print(sentence[0]) x += 1

TADA!πŸŽ‰. Looks through code. Hold the phony, there is a mistake. If you printed that out, then it will print Python is awesome, each letter will be printed out in a different lin. That's why we imported sys! To have the trusty function sys.stdout.write(). And it will print everything in just ONE line!


import sys sentence = ["P", "y", "t", "h", "o", "n", " ", "i", "s", " ", "a", "w", "e", "s", "o", "m", "e", "."] x = 0 for i in range(len(word)): sys.stdout.write(sentence[x]) x += 1

You can see the repl down below, and don't forgot to check my terrible BioπŸ’³!

Until my next...project/tutorial (I haven't been posting projects in a while...😜. I will manage to post one soon. Look at my profile for my animations!) Without further ado, a peace! falls of chair


Profile icon
Profile icon
Profile icon