

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find the String in a List
When it is required to find the string in a list, a simple ‘if’ condition along with ‘in’ operator can be used.
Example
Below is a demonstration of the same
my_list = [4, 3.0, 'python', 'is', 'fun'] print("The list is :") print(my_list) key = 'fun' print("The key is :") print(key) print("The result is :") if key in my_list: print("The key is present in the list") else: print("The key is not present in the list")
Output
The list is : [4, 3.0, 'python', 'is', 'fun'] The key is : fun The result is : The key is present in the list
Explanation
- A list of integers and strings is defined and is displayed on the console.
- A value for key is defined and is displayed on the console.
- An ‘if’ loop is used to check if the key is present in the list.
- If yes, the result is displayed on the console.
- Related Questions & Answers
- Convert a list to string in Python program
- Python program to convert a list to string
- Python program to find the largest number in a list
- Python program to find the smallest number in a list
- Python program to find the Decreasing point in a List
- Python program to find the second largest number in a list
- Python program to find all close matches of input string from a list
- Python program to find largest number in a list
- Program to find a good string from a given string in Python
- Python Program to Find the Length of a List Using Recursion
- Program to find folded list from a given linked list in Python
- Python Program to find mirror characters in a string
- Python Program to Find the Largest Element in a Doubly Linked List
- Program to find out the palindromic borders in a string in python
- Python program to find Cumulative sum of a list
Advertisements