PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] how to print a list like a string?

 September 15, 2022     list, printing, python     No comments   

Issue

I am trying to print a list like a string:

    list = ['a', 'b', 'c', 'd', 'e', 'f']

the output I want it to be;

    abcdef

Solution

You should use the join() method, in python, join() returns a string in which the string elements of sequence have been joined by str separator.

str = ''
sequence = ['a', 'b', 'c', 'd', 'e', 'f']
print str.join(sequence)

You can pass any list or tuple as sequence.



Answered By - SpiXel
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing