GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing codescracker.com — Python in Keyword
Python in KeywordThe "in" keyword in Python is used when we need either:
For example: x = [12, 23, 65, 87] if 23 in x: print("23 is available in the list 'x'") else: print("23 is not available in the list 'x'") print("\nAll elements of list 'x':") for e in x: print(e) The output of the above program is shown in the screenshot below to show how the "in" keyword works in Python: Note: Python is a case-sensitive language; therefore, keep both the letters of "in" in small letters. Python in Keyword ExampleHere is an example of the "in" keyword in Python: x = (134, 54, 65, 67, 0, 23) print("Enter a Number: ", end="") num = int(input()) if num in x: print("\nThe number is available") else: print("\nThe number is not available") print("\nEnter a String: ", end="") str = input() print("\nCharacters of given string are:") for c in str: print(c) A sample run with user input 66 as a number and Python as a string is shown in the snapshot given below: The "in" keyword can be thought of as a membership operator that returns True or False depending on whether or not the value is in the container. Advantages of the "in" keyword in Python
Disadvantages of the "in" keyword in Python
« Previous Tutorial Next Tutorial » Practice Quizzes
Test your programming and computer science knowledge with interactive MCQs and topic-based quizzes. Popular Topics
Explore the most popular programming and computer science tutorials on CodesCracker. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |