-1

I'm a beginner learning to use Python, and the IDE that use is Atom. But whenever I use a function, it just gives me the time taken to perform the task with a blank result. Any help?

python

def hello_func()
    print('Hello World')

print(hello_func())

expect it to print the string but instead end up getting a blank, no error message or anything just blank

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129

2 Answers2

0

obviously you have indentation problems, I think you are doing it like this but I'm not sure:

def hello_func():
    print('Hello World')

    print(hello_func())
 #output: Process finished with exit code 0

if you are writing you code like that then you are not calling the function and that's why nothing will be printed!

to fix this you need to write it like this

def hello_func():
    print('Hello World')

print(hello_func()) # output will be hello world printed and then None

now the answer why it is printing the statement and then None you can find it here

basilisk
  • 1,156
  • 1
  • 14
  • 34
-2

To print a function, the function needs to return a value.

def hello_func():
    return 'Hello World'

print(hello_func())
clubby789
  • 2,543
  • 4
  • 16
  • 32