I am wondering, is there a way to use the input() function inside a user-defined function? I tried doing this
def nameEdit(name):
name = input()
name = name.capitalize
return name
chepner
538k77 gold badges595 silver badges747 bronze badges
-
1And...? Does it give an error?Islay– Islay2014年06月04日 19:27:27 +00:00Commented Jun 4, 2014 at 19:27
2 Answers 2
Using input is fine. However, you aren't calling name.capitalize; you're just getting a reference to the method and assigning that to name. [Further, as pointed out by Bob, your function doesn't need a name argument.] The correct code would be
def nameEdit():
name = input()
name = name.capitalize()
return name
or more simply:
def nameEdit():
return input().capitalize()
answered Jun 4, 2014 at 19:24
chepner
538k77 gold badges595 silver badges747 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Bob
There shouldn't be a need to pass in a name argument to the method since it isn't actually being used. Unless I'm missing something.
Are you talking about asking for input from a user from a method? If so then this would be what you're looking for:
def nameEdit():
name = input("Enter your name: ")
name = name.capitalize()
return name
lang-py