2 questions about dot notation .isalpha()


#1


https://www.codecademy.com/en/courses/python-beginner-2W5v7/0/5?curriculum_id=4f89dab3d788890003000096#

My code works, but I have 2 questions regarding it.

It seems as though both of these codes work:

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")

if len(original) > 0 and original.isalpha():
    print original

else:
    print "empty"



as well as:

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")

if len(original) > 0 and str(original).isalpha():
    print original

else:
    print "empty"


which leads to 2 questios I have in mind:

  1. I thought that dot notation such as .isalpha() is only reserved for strings (like .upper() and .lower() ) but why does original.isalpha() work as well when original is a variable?

  2. Does .isalpha() require a colon or only the if statement? Because I notice that there is only one : placed after the .isalpha()

Thank you very much for the help! I am, unfortunately, completely new to Python :frowning:


#2

Because the variable original holds a string, .upper() would also work on a variable holding a string:

test = "i will be uppercase"
print test.upper()

See? works fine.

Uhm.. that is just the colon of the if statement, which is at the end, if you had 3 conditions:

if a > b and b > c and c > d:

the colon would be at the very end, it is part of the if statement


#3

I see...thanks for the help! :smiley: