Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How do we grep a particular keyword from Python tuple?
If you have a tuple of strings and you want to search for a particular string, You can use the in operator.
example
tpl = ("Hello", "world", "Foo", "bar")
print("world" in tpl)
Output
This will give the output −
True
Example
If you want to check if there is a substring present. You can loop over the tuple and find it using:
tpl = ("Hello", "world", "Foo", "bar")
for i in tpl:
if "orld" in i:
print("Found orld in " + i )
Output
This will give the output −
Found orld in world
Advertisements
