Why can't I force an int to be a string? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Why can't I force an int to be a string? (/thread-8302.html) |
Why can't I force an int to be a string? - fad3r - Feb-13-2018 It just doesn't work. I am familiar with str(10). Here is my code. This is driving me crazy. #Inputs b = " is awesome" c = 10 list1 =[] output_dict={} input_list = ['mike', 1, 'leon', 2, 'david', 3] #Function def listed(a): if "str" in str(type(a)): d = a + b return (d) else: e = a + c str(e) print (type (e)) return (e) # for x in input_list: list1=listed(x) # list(list1) # print (type (list1)) # # output_dict=zip(list1, input_list) # # printIt just returns class int and because of that I am not able to use the zip function later on. RE: Why can't I force an int to be a string? - Larz60+ - Feb-13-2018 you are asking for the type of e print (type (e))if you want to print 'e', it's just: print(e) RE: Why can't I force an int to be a string? - fad3r - Feb-13-2018 I want E to be string instead of a integer so that list1 can be used in zip otherwise I get: File "C:/Users/c0unt3rpl4y/PycharmProjects/House/Challenges/Archive/Challenge 6.py", line 52, in <module> list(list1) TypeError: 'int' object is not iterable That is with me trying to use the list command on list1. If I remove that (turning list1 into a list) which was my other try I get: output_dict=zip(list1, input_list) TypeError: zip argument #1 must support iteration Basically I need the result of E to become a string so that i can use it in zip later. RE: Why can't I force an int to be a string? - Larz60+ - Feb-13-2018 need to also change: str(e)to e = str(e) RE: Why can't I force an int to be a string? - fad3r - Feb-13-2018 You're a genius Larz. Thank you buddy. |