2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pythonのfor文(match文)python3.10~

Last updated at Posted at 2024-03-22

phpなどでは、子の変数にはこの数字しかない!答えが一つしかないときはif文よりswich文。

swich文がpythonでは実装されていなかったが、python3.10よりmatch文として実装。

face = ['','','','','','']
for f in face:
    match f:
        case'':
            print('eyes')
        case'':
            print('mouth')
        case'':
            print('nose')
        case'':
            print('throat')
        case'':
            print('ear')
        case n:
            print(n + 'は存在しない')
    #出力結果
    eyes
    mouth
    nose
    throat
    ear
    手は存在しない
2
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?