per page, with , order by , clip by
Results of 1 - 10 of about 102 for else (0.006 sec.)
4. その他の制御フローツール 11659
4. その他の制御フローツール 前章で紹介した while 文の他にも、 Python にはいくつか制御フローツールがあり、本章で説明します。 4.1. if 文 おそらく最もおなじみの文型は if 文でしょう。例えば: >>> x = int ( input ( "Please enter an integer: " )) ... . print ( 'Negative changed to zero' ) ... elif x == 0 : ... print ( 'Zero' ) ... elif x == 1 : ... print ( 'Single' ) ... else : ... print ( 'More' ) ... More ゼロ個以上の elif 部を使うことができ、 else 部を付けることもできます。キーワード ' elif ' ... は 'else if' を短くしたもので、過剰なインデントを避けるのに役立ちます。一連の if ... elif ... elif ... は、他の言語における switch ... 偶数 4 を見つけた 奇数 5 を見つけた 偶数 6 を見つけた 奇数 7 を見つけた 偶数 8 を見つけた 奇数 9 を見つけた 4.5. ループの else 節 for または while ループ中の break 文は else 節と対になる場合があります。 break を実行せずにループが終了すると、 else 節 ...
https://man.mtool.work/python/3.14/tutorial/controlflow.html
itertools --- 効率的なループ用のイテレータ生成関数群 11348
itertools --- 効率的なループ用のイテレータ生成関数群 このモジュールは イテレータ を構築する部品を実装しています。プログラム言語 APL, Haskell, SML からアイデアを得ていますが、 Python に適した形に修正されています。 このモジュールは、高速でメモ ... tuple ( pool [ i ] for i in indices ) while True : for i in reversed ( range ( r )): if indices [ i ] != i + n - r : break else : return indices [ i ] += 1 for j in range ( i + 1 , r ): indices [ j ] = indices [ j - 1 ] + 1 yield tuple ( pool [ i ] f ... eld tuple ( pool [ i ] for i in indices ) while True : for i in reversed ( range ( r )): if indices [ i ] != n - 1 : break else : return indices [ i :] = [ indices [ i ] + 1 ] * ( r - i ) yield tuple ( pool [ i ] for i in indices ) Added in version 3 ... B')] → A B C D A B # [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D keyfunc = ( lambda x : x ) if key is None else key iterator = iter ( iterable ) exhausted = False def _grouper ( target_key ): nonlocal curr_value , curr_key , exhausted ...
https://man.mtool.work/python/3.14/library/itertools.html
10. 完全な文法仕様 11193
10. 完全な文法仕様 以下は Python の完全な文法で、CPython のパーサを生成するための文法から直接得たものです ( Grammar/python.gram を参照)。 ここでは、コード生成とエラー回復に関する詳細を省略しています。 ここで使う記法は、これまでのドキュメント ... NEWLINE # Not needed, there for speedup | ';' . simple_stmt + [ ';' ] NEWLINE # NOTE: assignment MUST precede expression, else parsing a simple assignment # will throw a SyntaxError. simple_stmt : | assignment | type_alias | star_expressions | retur ... lt # If statement # ------------ if_stmt : | 'if' named_expression ':' block elif_stmt | 'if' named_expression ':' block [ else_block ] elif_stmt : | 'elif' named_expression ':' block elif_stmt | 'elif' named_expression ':' block [ else_block ] else_ ... block : | 'else' ':' block # While statement # --------------- while_stmt : | 'while' named_expression ':' block [ else_block ] # For stat ...
https://man.mtool.work/python/3.14/reference/grammar.html
8. 複合文 (compound statement) 10727
8. 複合文 (compound statement) 複合文には、他の文 (のグループ) が入ります; 複合文は、中に入っている他の文の実行の制御に何らかのやり方で影響を及ぼします。一般的には、複合文は複数行にまたがって書かれますが、全部の文を一行に連ねた単純な書き方も ... ッダに続く行で一つ多くインデントされた文の集まりです。後者の形式のスイートに限り、さらに複合文をネストできます; 以下の文は、 else 節がどちらの if 節に属するかがはっきりしないなどの理由から不正になります: if test1 : if test2 : print ( x ) また、このコン ... 、オプションの継続節は必ず、文を開始できない予約語で始まるので、曖昧さは存在しません。 (Python では、 'ぶら下がり (dangling) else ' 問題は、ネストされた if 文をインデントさせることで解決されます)。 以下の節における文法規則の記述方式は、明確さのために、 ... 岐を実行するために使われます: if_stmt : "if" assignment_expression ":" suite ( "elif" assignment_expression ":" suite )* [ "else" ":" suite ] if 文は、式を一つ一つ評価してゆき、真になるまで続けて、真になった節のスイートだけを選択します (真: true と偽: ...
https://man.mtool.work/python/3.14/reference/compound_stmts.html
タイマーファイル記述子 HOWTO 10106
タイマーファイル記述子 HOWTO リリース : 1.13 この HOWTO では、Linux のタイマーファイル記述子を Python で使う方法を説明します。 使用例 次の例は、タイマーファイル記述子を使って 1 秒に 2 回関数を実行する方法を示します。 # 実用的なスクリプトでは ... 例外を捕捉するべき。 cmd = data . decode () if cmd . startswith ( "stop" ): print ( f "Stopping server" ) is_active = False else : print ( f "Unknown command: { cmd } " ) else : # これ以上データがないので接続を閉じる print ( f "Closing connection { fd ... os . read ( fd , 8 ), byteorder = sys . byteorder ) print ( f "Timer { fds . index ( fd ) + 1 } expired { count } times" ) else : print ( f "Unknown file descriptor { fd } " ) finally : for fd in fds : ep . unregister ( fd ) os . close ( fd ) ep . cl ... ception for safety. cmd = data . decode () if cmd . startswith ( "stop" ): print ( f "Stopping server" ) is_active = False else : print ( f "Unknown command: { cmd } " ) else : # No more data, close connection print ( f "Closing connection { fd } " ) ...
https://man.mtool.work/python/3.14/howto/timerfd.html
Argparse チュートリアル 9187
Argparse チュートリアル author : Tshepang Mbambo このチュートリアルでは、 argparse を丁寧に説明します。 argparse は、Python 標準ライブラリの一部であり、おすすめのコマンドライン引数の解析モジュールです。 注釈 標準ライブラリには、コマンドライ ... e_args () answer = args . square ** 2 if args . verbose : print ( f "the square of { args . square } equals { answer } " ) else : print ( answer ) 出力は以下のようになります: $ python prog.py usage: prog.py [-h] [-v] square prog.py: error: the follow ... of { args . square } equals { answer } " ) elif args . verbosity == 1 : print ( f " { args . square } ^2 == { answer } " ) else : print ( answer ) 実行してみましょう: $ python prog.py 4 16 $ python prog.py 4 -v usage: prog.py [-h] [-v VERBOSITY] squa ... of { args . square } equals { answer } " ) elif args . verbosity == 1 : print ( f " { args . square } ^2 == { answer } " ) else : print ( answer ) 実行してみましょう: $ python prog.py 4 -v 3 usage: prog.py [-h] [-v {0,1,2}] square prog.py: error: arg ...
https://man.mtool.work/python/3.14/howto/argparse.html
8. エラーと例外 9032
8. エラーと例外 これまでエラーメッセージについては簡単に触れるだけでしたが、チュートリアル中の例を自分で試していたら、実際にいくつかのエラーメッセージを見ていることでしょう。エラーには (少なくとも) 二つのはっきり異なる種類があります。それは ... pt Exception as err : print ( f "予期せぬエラー { err =} , { type ( err ) =} " ) raise try ... except 文には、オプションで else 節 (else clause) を設けることができます。 else 節を設ける場合、全ての except 節よりも後ろに置かなければなりません。 else 節 ... 次のようにします: for arg in sys . argv [ 1 :]: try : f = open ( arg , 'r' ) except OSError : print ( arg , 'が開けません' ) else : print ( arg , 'は' , len ( f . readlines ()), '行です' ) f . close () 追加のコードを付け加えるのは try 節よりも else 節の ... pt 節で処理されることがあります。 except 節で処理されなかった例外は、 finally 節の実行後に再送出されます。 except 節または else 節の実行中に例外が発生することがあり得ます。その場合も、 finally 節が実行された後に例外が再送出されます。 finally 節が bre ...
https://man.mtool.work/python/3.14/tutorial/errors.html
numbers --- 数の抽象基底クラス 8722
numbers --- 数の抽象基底クラス ソースコード: Lib/numbers.py numbers モジュール ( PEP 3141 ) は、下位になるほど多くの演算を定義する、数値の 抽象基底クラス の階層を定義しています。 このモジュールで定義する型は、どれもインスタンス化を目的とした ... g_stuff ( self , other ) elif isinstance ( other , OtherTypeIKnowAbout ): return do_my_other_adding_stuff ( self , other ) else : return NotImplemented def __radd__ ( self , other ): if isinstance ( other , MyIntegral ): return do_my_adding_stuff ( o ... : return float ( other ) + float ( self ) elif isinstance ( other , Complex ): return complex ( other ) + complex ( self ) else : return NotImplemented There are 5 different cases for a mixed-type operation on subclasses of Complex . All of the above ... return fallback_operator ( float ( a ), b ) elif isinstance ( b , complex ): return fallback_operator ( complex ( a ), b ) else : return NotImplemented forward . __name__ = '__' + fallback_operator . __name__ + '__' forward . __doc__ = monomorphic_op ...
https://man.mtool.work/python/3.14/library/numbers.html
What's New in Python 2.5 8566
What's New in Python 2.5 著者 : A.M. Kuchling この記事では Python 2.5 の新機能を説明します。 Python 2.5 の最終リリースは 2006 年 8 月に予定されており、 PEP 356 にリリース計画が記載されています。 Python 2.5 は 2006 年 9 月 19 日にリリースされ ... 値 A または B を返す式です。条件式により以下と同じ効果を持つ単一行代入式を書くことが出来ます: if condition : x = true_value else : x = false_value 構文についての退屈で終わりのない議論が python-dev と comp.lang.python の両方で続いてきました。投票では、 ... したが、明らかな過半数によって支持される構文はありませんでした。候補には C の cond ? true_v : false_v や if cond then true_v else false_v を含む、ほか 16 のバリエーションがありました。 Guido van Rossum は結果として意外な構文を選択しました: x = true_val ... ue if condition else false_value 評価はこれでも既存の Boolean 式のように遅延的であり、評価順は少々前後します。真ん中の condition はまさに最初に ...
https://man.mtool.work/python/3.14/whatsnew/2.5.html
email: 使用例 8411
email : 使用例 ここでは email パッケージを使って電子メールメッセージを読む・書く・送信するいくつかの例を紹介します。より複雑な MIME メッセージについても扱います。 まず、単純なテキストメッセージを作成して送信する方法を見てみましょう (テキスト ... 、次のようにします: headers = Parser ( policy = default ) . parsestr ( 'From: Foo Bar <user@example.com> \n ' 'To: <someone_else@example.com> \n ' 'Subject: Test message \n ' ' \n ' 'Body would go here \n ' ) # これで、辞書としてヘッダーの各項目にアク ... たは保存します if args . output : with open ( args . output , 'wb' ) as fp : fp . write ( msg . as_bytes ( policy = SMTP )) else : with smtplib . SMTP ( 'localhost' ) as s : s . send_message ( msg ) if __name__ == '__main__' : main () つぎに、上のよう ... tent () . splitlines (): print ( line ) sys . exit () elif richest [ 'content-type' ] . subtype == 'html' : body = richest else : print ( "Don't know how to display {} " . format ( richest . get_content_type ())) sys . exit () elif richest [ 'content ...
https://man.mtool.work/python/3.14/library/email.examples.html
PREV 1 2 3 4 5 6 7 8 9 10 NEXT