Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

Try

def hello(name):
    print('Hello, '+name+'!!!')
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top