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