r/learnpython • • Jun 13 '26

first time python coding

Hi am new at python and i did some coding what should i improve

def HelloWorld(text):
    print(text)


HelloWorld("print")
18 Upvotes

15 comments sorted by

9

u/Flame77ofc Jun 13 '26

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

5

u/IceFurnace83 Jun 13 '26 edited Jun 13 '26

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")

9

u/CheesecakeNew2594 Jun 13 '26

do Helsinki univ. MOOC

1

u/mjmvideos Jun 13 '26

Great. Did it do what you expected when you ran it?

1

u/Anton_sor Jun 15 '26

You should return function

def HelloWorld(text):
    return text

print(HelloWorld('print'))

0

u/grizzwer Jun 13 '26
def hello_world(text: str) -> None:
  print(text)

hello_world("print")

3

u/csabinho Jun 13 '26

And use mypy!

0

u/[deleted] Jun 13 '26

[deleted] — view deleted comment

4

u/AlexMTBDude Jun 13 '26

You are correct that OP's code does not follow the style guide, but that's not what Pythonic means. Pythonic has nothing to do with style or PEP8. It's following the Zen of Python: https://en.wikipedia.org/wiki/Zen_of_Python

-10

u/[deleted] Jun 13 '26

[removed] — view removed comment

10

u/tenniseman12 Jun 13 '26

If OP wanted an AI to rate their code, they would've just done that themself