Python Forum
Help Formatting Print Statement (input from 3 lists) X 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Formatting Print Statement (input from 3 lists) X 2
#9
Open a Python interpreter, create a small list of strings and run the code from my example. Use the created list in place of 'iterable', as an argument to join(). See what is the output. Get this and write it into a file. Do you know how to open a file for writing? How to write something in it?
You write in the file a string, right? Well '::'.join(iterable) will produce a string.

str is a data type just like int, float and so on. you do not use join() method like that: str.join(iterable).
'::' is a string like 'Alan', 'apple', 'rain' or 'How many Microsoft programmers does it take to change a lightbulb?' All of these are str type so they have method called join. For example: 'apple'.join(iterable). The 'iterable' must be a sequence of values. A list, tuple, or set. What you are doing is giving a single value to '::'.join(city). 'city' holds a single value, write.

Try this code
my_iterable = ['one', 'two', three', 'go']
my_string = ",".join(my_iterable)
print(my_string)
Or you may try with 'apple'.join(my_iterable)  Wink
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: Help Formatting Print Statement (input from 3 lists) X 2 - by wavic - Dec-01-2017, 04:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Post IF Statement Input OrphanedSoul 2 2,362 Jun-04-2021, 05:03 PM
Last Post: deanhystad
  Problem with print formatting using definitions Tberr86 2 2,039 Mar-20-2021, 06:23 PM
Last Post: DPaul
Bug How to print only vowels from an input? PP9044 8 7,620 Feb-26-2021, 04:02 PM
Last Post: Serafim
  Print user input into triangle djtjhokie 1 2,421 Nov-07-2020, 07:01 PM
Last Post: buran
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 3,582 Feb-27-2020, 09:22 AM
Last Post: buran
  Print the longest str from user input edwdas 5 4,199 Nov-04-2019, 02:02 PM
Last Post: perfringo
  How to print a statement if a user's calculated number is between two floats Bruizeh 2 2,424 Feb-10-2019, 12:21 PM
Last Post: DeaD_EyE
  if/else statement only outputs else statement regardless of input KameronG 2 2,650 Feb-08-2019, 08:04 AM
Last Post: KameronG
  How to force print statement to print on one line wlsa 4 3,594 Oct-28-2018, 09:39 PM
Last Post: wavic
  Print The Length Of The Longest Run in a User Input List Ashman111 3 3,238 Oct-26-2018, 06:56 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020