- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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