Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Truques no Python - Checando se uma string contém uma substring
- Artigo no LinkedIn:
- https://www.linkedin.com/pulse/truques-python-checando-se-uma-string-contém-diego-mendes-rodrigues/
- Curso de Python 3:
- https://produto.mercadolivre.com.br/MLB-991504015-curso-de-python-3-_JM
- Diego Mendes Rodrigues
- '''
- string = 'Olá mundo' # Exemplo True
- # string = 'Até mais' # Exemplo False
- # Forma 'convencional'
- if string.find('Olá') != -1:
- print('Successo! Olá é uma substring!')
- # Forma 'elegante' utilizando 'if substring in string'
- if 'Olá' in string:
- print('Successo! Olá é uma substring!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement