Home > Software design >  Print array value without brackets in Python
Print array value without brackets in Python

Time:06-29

So, I have an array value like this

"Items": [
            "*.abc.com",
            "*.xyz.me"
        ]

with print(Items) it's returning ['*.abc.com', '*.xyz.me'] but, I want to print everything without brackets like '*.abc.com', '*.xyz.me'

Followed some way, but those are returning different not exactly what I want.

CodePudding user response:

what about this?

t = [
            "*.abc.com",
            "*.xyz.me"
        ]

t = str(t)
print(t[1:-1])

Output:

'*.abc.com', '*.xyz.me'

i add a short description like mozway suggests:

you convert your python list to a string (at this step the [ ] are still there). After that, you print the string, strarting at index 1, (include) (so it's excludes the first one who is '[') until the last one (exclude) who is ']'

CodePudding user response:

You can try:

for i,x in enumerate(item):
    if i==len(item)-1:
        print(x)
    else:
        print(x,end=', ')
print()
  • Related