Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use the in keyword #210

Merged
merged 2 commits into from Oct 17, 2021
Merged

fix: Use the in keyword #210

merged 2 commits into from Oct 17, 2021

Conversation

arnu515
Copy link
Contributor

@arnu515 arnu515 commented Oct 9, 2021

Using the in keyword is faster than having multiple equality statements.

Example:

test = input()

# Using ==
if test == "yes" or test == "y" or test == "oui":
  print("You agreed")
elif test == "no" or test == "n" or test == "non":
  print("You disagreed")

# Using in
if test in ["yes", "y", "oui"]:
  print("You agreed")
elif test in ["no", "n", "non"]:
  print("You disagreed")

See how much easier the second option is to read, correct and spot errors? Plus, it is faster to use in than comparing multiple times.

LMK if you need any changes :)

arnu515 and others added 2 commits October 9, 2021 15:56
Using the `in` keyword is faster than having multiple equality statements
@SathyaBhat
Copy link
Owner

Thanks for your contribution!

@SathyaBhat SathyaBhat merged commit 8346f98 into SathyaBhat:master Oct 17, 2021
@arnu515 arnu515 deleted the patch-1 branch October 19, 2021 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants