The proper usage


#1


Hi all, I'm fairly confused at what this lesson is about. Why could I not run the code with the following instead?
Wouldn't I be correct since the description of the lesson says :

Let's take a closer look at why you use len(string) and str(object), but dot notation (such as "String".upper()) for the rest.

ministry = "The Ministry of Silly Walks"

print len("ministry")
print "ministry".upper()

ministry = "The Ministry of Silly Walks"

print len(ministry)
print ministry.upper()

Sincerely,
Brian!


#2

The first codebit, you are doing the len and .upper() on a string "ministry".
The second codebit, you are doing the len and .upper() on the variable, ministry that contains the string, "The Ministry of Silly Walks". Both "ministry" and ministry are strings except one is a string while the other contains a string.

Anything wrapped in quotation marks becomes the string data type.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.