Intermediate Python - Loop Data Structures
Can I get some help in understanding this part?
cars["COUNTRY"] = cars["country"].apply(str.upper)
brics["name_length"] = brics["country"].apply(len)
What is the difference between upper() and len?
Why need to add "str." to "upper"?
@basil-han is right.
For str.upper, we normally call it with my_string.upper(). It's a string method, ie. every string has access to this method.
For len, we normally call it with len(my_string). It's a built-in function.
str.upper simply returns a string where all characters are in upper case.
Example: Let's say you have a string "abc". After you apply the upper() method, your output result will become "ABC".
len method simply return the length of a given string.
Example: Let's say you have a string "abc". After you apply the len() method, output result will become 3.