Check if string only contains characters from list of characters/symbols?

前端 未结 4 1733
野的像风
野的像风 2021-01-28 03:44

How can I check in Python 3 that a string contains only characters/symbols from a given list?

Given:

  • a list allowedSymbols = [\'b\', \'c\', \'z\', \'
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-28 04:08

    I am not a python expert, but something below will work

     for c in enteredpass:
       if c not in allowedSymbols: 
          return 0
    

提交回复
热议问题