FAQ: Learn Python – Strings & Console Output – And Now, For Something Completely Familiar

This community-built FAQ covers the “And Now, For Something Completely Familiar” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy exercise And Now, For Something Completely Familiar:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

What does len() return? Does it return an int or a string?

Also, how can I figure out what a function returns from the documentation? I tried looking for documentation for the len() function and I found the following (which has no information about the return type):

len ( s )
Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).

Always returns an integer.

Why does print len(my_string)
work if len returns an int?

print () does not care about data types; that is, if the data type is consistent. It will kick back if we mix data types in a single expression.

print ("length: ", len(my_string))

will work since the inputs are comma separated.

print ("length: " + len(my_string))

will not work, since there are mixed data types in the single expression.

print ("length: " + str(len(my_string)))

will work since we have cast the int to a str.

1 Like

Thank you for your reply!

Can you please elaborate on when we would separate inputs with commas?

When it is only necessary to get all the output on one line, non-formatted would be a use case. It’s not a form of concatenation, though, since there is no linking of the objects into a single string except in the display. In fact, this is probably the least used method of printing so don’t read too much into it.

1 Like

There’s a bug in .upper:

#set string : Copy the text from the description:
my_String = “string you’d like”
print my_string.upper()

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe2 in position 10: ordinal not in range(128)

It’s likely you’ve accidentally caught a character or similar accidentally e.g. with copy/paste when ascii only contains '. For more details on Python2 and character encoding see-Unicode HOWTO — Python 2.7.18 documentation. Hopefully you can see the difference between the two anyway; the following questions discusses the same thing-