Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't figure this one out
#2
(May-14-2017, 07:39 PM)Stefython Wrote: I'm brand new to programming, busy practicing some coding. What am I doing wrong here? Confused 

>>>farm_equipment = ["jd r4038", "jd 9620", "jd 9630", "jd 4455", "jd 6140d", "jd 9860", "jd 9870", "jd seeder"]
>>>message_c = "\nList of current equipment: "
>>>print(message_c + farm_equipment)


I'm getting the following error:

Traceback (most recent call last):
  File "every_function_c3.py", line 17, in <module>
    print(message_c + farm_equipment)
TypeError: must be str, not list

You are trying to add incompatible types - string and list. You can print either directly - though in case of list it may look strange to you.

In order to concatenate, you have to convert list to string - one of the usual methods is to join it
    print(message_c + ', '.join(farm_equipment))
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
Can't figure this one out - by Stefython - May-14-2017, 07:39 PM
RE: Can't figure this one out - by volcano63 - May-14-2017, 07:56 PM
RE: Can't figure this one out - by metulburr - May-14-2017, 07:58 PM
RE: Can't figure this one out - by wavic - May-14-2017, 08:01 PM
RE: Can't figure this one out - by Stefython - May-14-2017, 08:59 PM
RE: Can't figure this one out - by metulburr - May-14-2017, 09:10 PM
RE: Can't figure this one out - by wavic - May-15-2017, 03:04 AM

Forum Jump:

User Panel Messages

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