Python鍩虹涔嬫牸寮忓寲杈撳嚭銆佽繍绠楃銆佹暟瀛椾笌甯冨皵鍊间簰鎹互鍙妛hile...else
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python鍩虹涔嬫牸寮忓寲杈撳嚭銆佽繍绠楃銆佹暟瀛椾笌甯冨皵鍊间簰鎹互鍙妛hile...else相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%bc%98%e5%85%88%e7%ba%a7' title='浼樺厛绾?>浼樺厛绾?/a> 鍙栨暣 鏉′欢 浼樺厛 input 蹇呴』 娆℃柟 閫昏緫杩愮畻
python鏄竴澶╁涓€鐐癸紝灏辫繖鏍烽浂闆剁纰?hellip;…
鏍煎紡鍖栬緭鍑?/span>
銆€銆€%鏄崰浣嶇锛?s鏄瓧绗︿覆鏍煎紡,%d鏁存暟鏍煎紡锛?f鏄诞鐐规暟鏍煎紡
1 name = input(鈥?/span>杈撳叆濮撳悕鈥?/span>) 2 age = input(鈥?/span>杈撳叆骞撮緞鈥?/span>) 3 str = 鈥?/span>骞撮緞锛?d,濮撳悕锛?s鈥?/span> %(int(age),name) 4 str = 鈥?/span>骞撮緞锛?s,濮撳悕锛?s鈥?/span> %(age,name) 5 print(str)
鍥犱负input榛樿杈撳叆鐨勬槸绫诲瀷鏄瓧绗︿覆锛屾墍浠ュ嵆渚胯緭鍏ヤ竴涓暟瀛楋紝鍏舵牸寮忓寲涔熸槸%s 锛屼絾鏄鏋滄兂鐢?strong>%d鏍煎紡杈撳嚭锛屽垯闇€鍏?strong>寮哄埗杞崲鎴恑nt绫诲瀷
while...else
銆€銆€鐢ㄥ杈冨皯锛?浣嗗繀椤荤煡閬撱€?/span>
銆€銆€褰搘hile寰幆琚玝reak鎵撴柇锛屽嵆婊¤冻if鏉′欢锛屽氨涓嶄細鎵цelse鐨勭粨鏋溿€?/span>
銆€銆€褰揻or銆亀hile寰幆鍏ㄩ儴瀹屾垚锛宔lse鎵嶆墽琛屻€?/span>
杩愮畻绗?/span>
銆€銆€鎶涘紑鍔犲噺涔橀櫎鍜屽彇妯★紝杩欎簺閮芥槸璺烠涓€鏍风殑锛岀壒鍒殑鏄湪python涓?*琛ㄧず骞傦紝渚嬪锛?/span>
1 print(2**8) #琛ㄧず2鐨勫叓娆℃柟锛岀粨鏋?56
銆€銆€姝ゅ锛?rdquo;//“琛ㄧず鏁撮櫎锛屽嵆鍙栨暣锛岃嫢鍟嗘湁灏忔暟閮ㄥ垎锛屽垯鍙?杩斿洖鏁存暟閮ㄥ垎锛岀被浼间簬C璇█鐨?rdquo;/“
閫昏緫杩愮畻绗?/h1>
銆€銆€浼樺厛绾э細not > and > or锛岃嫢鏄湁鎷彿鐨勶紝鎷彿浼樺厛绾ф渶楂樸€?/p>
銆€銆€ x or y锛寈涓洪潪闆讹紝鍒欒繑鍥瀤锛寈涓洪浂锛堝嵆涓哄亣锛夛紝杩斿洖y銆?/p>
銆€銆€ x and y锛?x涓洪潪闆讹紝鍒欒繑鍥瀥锛寈涓洪浂锛堝嵆涓哄亣锛夛紝杩斿洖x銆傘€€
1 print(1 or 2)#1 2 print(0 or 2)#2 3 print(1 and 2)#2 4 print(0 or 2)#0 5 print(2 or 100 or 3 or 4)#2 6 print(0 or 4 and 3 or 2)#3
銆€銆€閫昏緫杩愮畻鏈€鍚庤繑鍥炵殑缁撴灉鍙兘涓烘暟瀛楋紝涔熷彲鑳戒负甯冨皵鍊?/p>
1 print(2 or 1 < 3) #2 2 print(1 < 3 or 2) #True 3 print(3 > 1 or 2 and 4) #True
鏁板瓧涓庡竷灏斿€间簰鎹?/h1>
銆€int杞崲bool绫诲瀷锛岄潪闆跺嵆涓篢rue(娉細璐熸暟涔熺畻闈為浂锛?锛岄浂涓篎lase
1 print(bool(1)) #杩斿洖Ture 2 print(bool(-1)) #杩斿洖Ture 3 print(bool(0)) #杩斿洖False
銆€銆€bool杞琲nt绫诲瀷锛孴rue涓?锛孎lase涓?
1 print(int(True)) #杩斿洖1 2 print(int(False)) #杩斿洖0
以上是关于Python鍩虹涔嬫牸寮忓寲杈撳嚭銆佽繍绠楃銆佹暟瀛椾笌甯冨皵鍊间簰鎹互鍙妛hile...else的主要内容,如果未能解决你的问题,请参考以下文章
Bash 涓娇鐢ㄦ帶鍒惰繍绠楃杩炴帴鍛戒护 | Linux 涓浗