Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

How Can I Remove The Error Bad Operand Type For Unary +: 'Str'. In A My Looped Sentence

Asked by Anisha Dalal Nov 21, 2022 1.8K views 1 answer
Share

About this question

 The code works fine but the only problem I encountered an error is:

 bad operand type for unary +: 'str'.

This is my code:
express_file = {'TPLEX':'Pangasinan', 'SLEX':'Subic', 'Cavitex':'Bacoor,Cavite','MCX':'Muntinlupa','Star Tollway':'Laguna'}
for x,y in express_file.items():
    print(x,'runs through',+y+ '.')
print('The following Expressway are included in this data set:')
for x in express_file.keys():
    print(x)
print('nThe following Provinces are included in this data set:')
for x in express_file.values():
    print(x)
----------------------------------------------------------------
TypeError Traceback (most recent call last)
 in 
      1 express_file = {'TPLEX':'Pangasinan', 'SLEX':'Subic', 'Cavitex':'Bacoor,Cavite','MCX':'Muntinlupa','Star Tollway':'Laguna'}
      2 for x,y in express_file.items():
----> 3 print(x,'runs through',+y+ '.')
      4 print('The following Expressway are included in this data set:')
      5 for x in express_file.keys():
TypeError: bad operand type for unary +: 'str'

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.