Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (anonymous):

This doesn't refer to any particular problem set. I'm simply trying to convert the data type from str to int. Using the online tutorials this shouldn't be a problem, but I just cannot see me error. Here's what I typed into the Python Shell: IDLE 1.2.4 >>> data_type_conversion = '7' >>> type(data_type_conversion) >>> int(data_type_conversion) 7 >>> type(data_type_conversion) >>> data_type_conversion = data_type_conversion + 1 Traceback (most recent call last): File "", line 1, in data_type_conversion = data_type_conversion + 1 Type

OpenStudy (anonymous):

your variable "data_type_conversion" is still pointing to the string '7'. to change it to point to integer 7 you need to reassign it so...data_type_conversion=int(data_type_conversion)

OpenStudy (anonymous):

Thanks! I mistakenly thought typing "int(data_type_conversion)" handled the new assignment. I'll remember to use the proper assignment next time.

OpenStudy (anonymous):

the interpreter can make things kind of confusing because it immediately displays the value for the function you use, making it easy to think that it has assigned it to the variable. I've made the same mistake before lol another tricky thing is that multiplying string will still work, so for instance, if you multiplied by 2 the result would be '77' not 14, which might be hard to debug in a program since it won't give you an error.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!