Dúvida sobre 'in' e o EP6

Dúvida sobre 'in' e o EP6

by Rony dos Santos Teles -
Number of replies: 3

Fazendo uns testes no EP6 e no IDLE do Python, descobri algo estranho acontecendo.

# ===========================

>>> LETRAS = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

>>> type(LETRAS)
<class 'str'>
>>> 'n' in LETRAS
True
>>> 'f' in LETRAS
True
>>> 'nf' in LETRAS
False

# ===========================

Por qual motivo o 'nf' consta como não aparecendo em LETRAS?

In reply to Rony dos Santos Teles

Re: Dúvida sobre 'in' e o EP6

by Arthur Franco Perin Cruz -

Professor, me corrija se eu estiver errado, mas no caso o IDLE entende 'nf' como uma string conjunta,  e não como letras separadas... Então de fato nf não consta na lista... tenta fazer o teste se por exemplo, 'fg' consta na lista... o retorno provavelmente será True.

In reply to Arthur Franco Perin Cruz

Re: Dúvida sobre 'in' e o EP6

by José Coelho de Pina -

Certo, em Python "'bla' in uma_string" significa "'bla' é um substring de uma_string?"

Python 3.4.3 (default, Mar 26 2015, 22:07:01) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> LETRAS = "nf"
>>> 'nf' in LETRAS
True
>>> 'fn' in LETRAS
False
>>> VOGAIS = 'aeiou'
>>> 'ae' in VOGAIS
True
>>> 'ea' in VOGAIS
False
>>> 'ai' in VOGAIS
False
>>> 'ei' in VOGAIS
True
>>> 'i' in VOGAIS
True
>>>