selfteaching / selfteaching/selfteaching-python-camp

Day05 查找find函数用法相关资料的时候,对示例里的运行结果不理解

Open
#4,789 1 comment 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

如图看到了如下两段代码:
第一段:
str = "01213456"

if str.find("23"):
print ("YES!")
else:
print ("NO!")
第二段:
str = "01213456"

if str.find("01"):
print("YES!")
else:
print ("NO!")
两段运行的结果分别为1:YES! 2:NO!
不能理解为什么会出现这种不同。

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 file or test is named in the issue. Start by checking Python's str.find return values and how integers are evaluated in an if condition; done means explaining why the two examples print different results, preferably with a corrected condition or clearer example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.