selfteaching / selfteaching/selfteaching-python-camp

Day10 关于输出结果的问题,为何不能直接用print(test(x)),而要用y=test(x) print(y)???

Open
#449 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

#这是一个返回值的表示测试,如果x大于2则返回x,如果x小于等于2,则返回0.(失败)

def test(x):#这里用来定义返回规则
    if x > 2:
        return x
    else:
        return 0

x = int(input("shuruyigeshuzi:"))#这里进行输入,限制输入值为整数
print(test(x))#输出返回的值

#这是一个返回值的表示测试,如果x大于2则返回x,如果x小于等于2,则返回0.(成功)

def test(x):#这里用来定义返回规则
    if x > 2:
        return x
    else:
        return 0

x = int(input("shuruyigeshuzi:"))#这里进行输入,限制输入值为整数
y = test(x)#定义y等于返回的值
print(y)#输出返回的值

#上面是我自己写的关于返回一个值的测试,但是没弄懂为何不能用print(test(x)),直接请求返回结果,而加上y=test(x) print(y)后,就可以了。求解!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file, test, or entry point is named. Start by reproducing the two Python snippets and reviewing the issue's question about function return values and print behavior. Done means adding a clear explanation to the appropriate learning material or closing the question with an explanation, if no documentation change is requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.