Python virknes identifikators ()

Metode isidentifier () atgriež vērtību True, ja virkne ir derīgs Python identifikators. Ja nē, tas atgriež False.

Sintakse isidentifier()ir:

 string.isidentifier ()

isidentifier () Parametri

isidentifier()Metode neveic nekādus parametrus.

Atgriešanās vērtība no identifikatora ()

The isidentifier()metode atgriež:

  • Patiesi, ja virkne ir derīgs identifikators
  • Nepatiesa, ja virkne nav nederīgs identifikators

1. piemērs: Kā darbojas identifikators ()?

 str = 'Python' print(str.isidentifier()) str = 'Py thon' print(str.isidentifier()) str = '22Python' print(str.isidentifier()) str = '' print(str.isidentifier())

Rezultāts

 True False Nepatiesa False

Apmeklējiet šo lapu, lai uzzinātu, kas ir derīgs Python identifikators?

2. piemērs: Vairāk identifikatora () piemēru

 str = 'root33' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.') str = '33root' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.') str = 'root 33' if str.isidentifier() == True: print(str, 'is a valid identifier.') else: print(str, 'is not a valid identifier.')

Rezultāts

root33 ir derīgs identifikators. 33root nav derīgs identifikators. 33. sakne nav derīgs identifikators.

Interesanti raksti...