문제

I am trying to get a simple program to take command line arguments and print them out. Any name plus a character string of explanation marks. example: Bob !!!!

import sys

def hello(name):
    name = name + "!!!!"
    print(hello,name)

def main():
    hello(sys.argv[1])

main()

It correctly prints out Bob!!!!, but with also some other stuff:

function hello at 0x7f69465145f0 Bob!!!! with < > around the whole thing except Bob!!!!

I am not sure why it will not simply print out, Bob!!!!, normally without the other stuff.

Also, the mix of number/letters within the < > changes every time I run it. The function hello at and Bob!!!! stays the same.

도움이 되었습니까?

해결책

It's because hello is the name of function you've defined, thus print(hello, name) prints both the function object, and the string variable. If you want to print hello Bob !!!!!, use print('hello', name) instead.

다른 팁

Try

def hello(name):
    print('Hello, '+name+'!!!')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top