Pythonã® islower() 㨠isupper() ã®å¤å®å¦çã®ã¯ã
islower() 㨠isupper() ã®é¢æ°ã§ããリファレンスããã£ã¨ç¢ºèªããããä»ã®è¨èªã®çµé¨ã®ããæ¹ã¯è±æåã®å°æåã大æåãå¤å®ããé¢æ°ã ã¨èªèããã人ãå¤ãã®ã§ã¯ãªããã¨æãã¾ã(èªåãããã§ãã)ã
ãããã注æãã¦ãã ãããã»ã¼ãã®èªèã§å¤§ä¸å¤«ãªã®ã§ããä¸é¨ã®å ´é¢ã§ã¯ã¯ããçºåãã¾ãã
â»æ£ç¢ºã«ã¯æ£ããæåãç解ãã¦ããªãã®ãåé¡ãªã®ããããã¾ãããä»è¨èªãã£ã¦ãå¤ãã®äººããã®è½ã¨ãç©´ã«ã¾ãã¾ãã£ã¦ orzãããã¥ã¡ã³ãã«æ³¨è¨å
¥ãã¨ãã¦ã¼ã
å®ä¾ãç´¹ä»ãã¾ãã islower() ã¯ä¸»ã«ä»¥ä¸ã®ãããªå ´åã«ä½¿ç¨ãããã¨æãã¾ãã
# -*- coding: utf-8 -*- if "abcABC".islower(): print u"ãã¹ã¦å°æåã§ã" else: print u"ãã¹ã¦å°æåã§ã¯ããã¾ãã"
ãã¡ãã«ã¯å¤§æåã® ABC ãåå¨ãããããã¡ããå¤å®ã¯ False ã¨ãªãããã¹ã¦å°æåã§ã¯ããã¾ãããã¨è¡¨ç¤ºããã¾ãã
åæ§ã«ä»¥ä¸ã®ãã¿ã¼ã³ã®å ´åã®å¤å®çµæã«ã¯ã¿ãªããç´å¾ã§ãããã¨æãã¾ãã
æåå | å¤å®çµæ |
---|---|
abcABC | False |
a | True |
A | False |
1 | False |
æååãªã("")ã®ã¨ã | False |
空ç½(" ")ã®ã¨ã | False |
ãããã以ä¸ã®å¤å®çµæã¯Pythonã«ä¸æ £ããªæ¹ã¯éåæãæããã®ã§ã¯ãªãã§ããããã
æåå | å¤å®çµæ |
---|---|
a1 | True |
aA1 | False |
a1b2c3 | True |
a b(éä¸ã«ç©ºç½) | True |
a/b | True |
1 ãå¤å®ããã¨ãã¯ãã¡ãã False ã¨ãªãã®ã§ãã a1 ã¨è±æåã®å°æåã¨æ··å¨ããæååã®å ´å㯠True ã¨ãªãã®ã§ãã
åæ§ã« isupper() ããã¡ãã®åä½ã¯ç´å¾ã§ãããã¨æãã¾ãã
æåå | å¤å®çµæ |
---|---|
A | True |
a | False |
æååãªã("")ã®ã¨ã | False |
空ç½(" ")ã®ã¨ã | False |
ãããããã¡ãã®å¤å®ã«ã¯éåæãæããæ¹ãããã®ã§ã¯
æåå | å¤å®çµæ |
---|---|
A1 | True |
aA1 | False |
A1B2C3 | True |
A B(éä¸ã«ç©ºç½) | True |
A/B | True |
islower() é¢æ°ã®ã¨ãã¨åæ§ã« A1 ã¨ããå ´å㯠True ãè¿ãã®ã§ãã
ãªããã¡ãã®ä»æ§ã§ããã¯ããã¯Windowsçã®Pythonã®ãã°ã®å¯è½æ§ã¯ãªãã®ãã¨æããä»ã®ç°å¢ã§ããã¹ããã¦ã¿ã¾ãããåæ§ã®çµæã§ããããã¡ãã®å¤å®ã§æ£ããä»æ§ã®ããã§ãã
ã¡ãªã¿ã«ç¢ºèªããç°å¢ã¨Pythonã®ãã¼ã¸ã§ã³æ å ±ã¯ä»¥ä¸ã¨ãªãã¾ãã
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32
FreeBSD(ãããã¤ã³ã¿ã¼ãããã®ç°å¢)
Python 2.4.5 (#2, May 22 2008, 13:38:36) [GCC 3.4.4 [FreeBSD] 20050518] on freebsd6
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
ã¾ã¨ã
islower()
å¤å® | æ¡ä»¶ | |
---|---|---|
True | å°æåã®ã¿ã®æåå | |
True | å°æå+大æåå°æåã®åºå¥ã®ç¡ãæåã®æåå | |
False | 大æåå°æåã®åºå¥ã®ç¡ãæåã®ã¿ã®æåå | |
False | 大æåãå«ã¾ããæåå |
isupper()
å¤å® | æ¡ä»¶ | ||
---|---|---|---|
True | 大æåã®ã¿ã®æåå | ||
True | 大æå+大æåå°æåã®åºå¥ã®ç¡ãæåã®æåå | ||
False | 大æåå°æåã®åºå¥ã®ç¡ãæåã®ã¿ã®æåå | ||
False | å°æåãå«ã¾ããæåå |
ä»è¨èªã¨åæ§ã®å¤å®ãè¡ãããå ´åã¯ä»¥ä¸ã®æ§ã«å¦çããå¿ è¦ãããã¾ãã
# -*- coding: utf-8 -*- flag = True s = "abc1def" for i in s: if not i.islower(): flag = False break if flag: print "'" + s + u"'ã¯å°æåã®ã¿ã®æååã§ã" else: print "'" + s + u"'ã¯å°æåã®ã¿ã®æååã§ã¯ããã¾ãã"
2008/06/24追è¨:
id:c-yanããã®ã³ã¡ã³ãã«ãããã£ã¨çãã³ã¼ãã§å¦çã§ãããã¨ãå¤æããã®ã§çããã¼ã¸ã§ã³ã®ãµã³ãã«ã追å ãã¾ã(c-yanãããããã¨ããããã¾ã)ã
# -*- coding: utf-8 -*- s = "abc1def" if all(i.islower() for i in s): print "'" + s + u"'ã¯å°æåã®ã¿ã®æååã§ã" else: print "'" + s + u"'ã¯å°æåã®ã¿ã®æååã§ã¯ããã¾ãã"
ã¡ãªã¿ã« help(all) ããã¨ä»¥ä¸ã®æ§ã«åºåããã¾ãã
Help on built-in function all in module __builtin__: all(...) all(iterable) -> bool Return True if bool(x) is True for all values x in the iterable.
ãã«ãã®å
容ã確èªããã¨
ã¤ãã¬ã¼ã¿ã®å
¨ã¦ã®ãã¼ã¿(ä»åã®å ´å㯠i.islower() )ã True ã®å ´åã®ã¿ãTrueãè¿ãããã以å¤ã¯ False ãè¿ãããã§ãã