0
0

大文字判定 Python3編

Last updated at Posted at 2024-01-03

これは解法が2つある
ひとつはそれぞれの言語で大文字判定メソッドがあればそれが使える
pythonの場合はisupper()(小文字はislower())

if str(input()).isupper() == True:
    print('YES')
else:
    print('NO')

(2024.01.04修正)
上記のような==TRUEというような書き方はPythonの書き方ではだめだそうです。
私もオリジナルのガイドを読んで初めて知りました。。。
なので修正しておきます。

if str(input()).isupper():
    print('YES')
else:
    print('NO')

もう1つはUnicordの番号を調べる方法
これはord()を使う
つまり、大文字の”A"と”Z"の間になければOKってことですね
UnicordはVBA屋時代のときにもお世話になってましたね

c = input()

if ord(c) >= ord("A") and ord(c) <= ord("Z"):
    print("YES")
else:
    print("NO")

(2024.01.04修正)
コメントを頂いたのですが、コメントのご提案が私のよりもっと直感的なので、こちらも
書き直しておきます

c = input()

if ord("A") <= ord(c) <= ord("Z"):
    print("YES")
else:
    print("NO")
0
0
2

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
0
0