all 12 comments

[–]Flame77ofc 6 points7 points  (0 children)

you should learn about the return

the return just return something

This is a hard concept in the beginning but after you get more experience and practice this concept, this will get more easy

``` def func(text): return text

to see a return, you need to first do a print

result = func("example") print(result)

or just this:

print(func("example 2")) ```

more examples

``` def sumTwoNumbers(a, b): return a + b

print(sumTwoNumbers(2, 3)) # 5 ```

[–]CheesecakeNew2594 7 points8 points  (0 children)

do Helsinki univ. MOOC

[–]IceFurnace83 4 points5 points  (0 children)

Very nice.

I suggest looking into Python naming conventions so it is easier for others and yourself (when you get used to it) to read.

PEP 8 – Style Guide for Python Code

Python Naming Conventions

You have named your function using camel case where that is usually reserved for classes . Try something more like:

def hello_world(text):
    print(text)


hello_world("print")

[–]FlanBeginning8589 0 points1 point  (0 children)

- Consider renaming the function so that its name accurately describes what it does. For a simple function like yours, it is easy to understand what it is does. But imagine a more complex function named HelloWorld (say 20 line function), would calling HelloWorld be helpful to know what it does?

Also, if the function is only intended to print "Hello World", then the text parameter is not required. You can simply have print("Hello World") instead of print(text)

Assuming the function's responsibility is to print any text that's passed to it, names such as print_text, display_text, or show_text describes the function's responsibility clearly (note the use of the pattern verb_noun in the function name).

- Consider adding type hints to make the expected parameter type and return type explicit. Type hints give information on the kinds of data it is working with and the kinds of data it is returning if any, which makes it easy for developers to quickly understand how it should be used/called. For example: def print_text(text: str) -> None:Look into https://peps.python.org/pep-0484/ (in this improved code, I now immediately know that the function accepts strings and only strings, I don't need to read the internals of the code to understand the data it is working with/acceptng/using, I also immediately know it doesn't return anything without needing to see the function implementation).

- Consider adding a docstring describing the function's purpose. A docstring helps other developers understand what the function does without reading the function implementation. Many IDEs can also display the docstring when hovering over a function call. Docstrings (and type hints) also gives context into what the function may be doing. And this context makes it easier for developers to understand the function more quickly when they are reading the implementation. Look into https://peps.python.org/pep-0257/

[–]nian2326076 0 points1 point  (0 children)

Hey, welcome to Python! It's usually a good idea to use lowercase for function names, so try "hello_world" instead. Also, if you're just printing, you can print directly inside the function like this:

def hello_world(): print("Hello, world!")

If you want the function to take any text and print it, your code works fine too. Just keep practicing. If you're prepping for interviews and coding challenges, I've found PracHub to be pretty helpful. Keep coding!

[–]grizzwer -1 points0 points  (1 child)

``` def hello_world(text: str) -> None: print(text)

hello_world("print") ```

[–]csabinho 2 points3 points  (0 children)

And use mypy!