请问如下一段代码,我如何用python3 提取到里面的数字(2.16 108.9)呢? 谁知道如何用python3写一段程序用input让人输一段话...
\u5982\u4f55\u7528python3\u5199\u4e00\u6bb5\u7a0b\u5e8f\u8ba9\u4eba\u8f93\u4e00\u6bb5\u8bdd\u53ef\u4ee5\u4e13\u95e8\u628a\u8fd9\u6bb5\u8bdd\u91cc\u7684\u6570\u5b57\u6311\u51fa\u6765\uff08\u6c42\u5927\u795e\u5e2e\u5fd9\uff09>>> import re>>> input_text = raw_input()1h2h3h45h5h6h87h8hm9>>> list1 = re.findall('[0-9]+',input_text)>>> list1['1', '2', '3', '45', '5', '6', '87', '8', '9']>>>
info = input('Please input something:\n')for x in info: if x.isdigit(): print x
\u6ce8\u610f\uff0c\u6211\u7528\u7684python3.3.5\uff0c\u6ca1\u6709raw_input\uff0c\u5982\u679c\u4f60\u7528\u7684python\u7248\u672c\u652f\u6301raw_input\uff0c\u53ef\u4ee5\u628ainput\u6362\u6210raw_input.
\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff0c\u6709\u7591\u95ee\u8bf7\u8ffd\u95ee\uff01
# !/usr/bin/python3.4
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
html = '<p class="nba-player-vitals__top-info-metric">2.16<abbr title="meters">m</abbr></p>, <p class="nba-player-vitals__top-info-metric">108.9<abbr title="kilograms">kg</abbr></p>'
soup = BeautifulSoup(html, "html.parser")
contents = soup.find_all("p",attrs={"class","nba-player-vitals__top-info-metric"})
for item in contents:
text = item.get_text()
print(text)
绛旓細绛:濡傛灉鎮ㄥ凡缁忔垚鍔熷畨瑁匬ython锛岄偅涔堝浜庡垵瀛﹁呮潵璇达紝浣犲彲浠ュ厛鍦ㄥ懡浠よ涓嬫墽琛屼竴浜涜鍙ュ幓鐪嬩竴涓嬫晥鏋溿 Python鍜孋璇█绛夋湁涓浜涗笉涓鏍凤紝瀹冨彲浠ラ愯瑙f瀽璇彞锛屽涓鎵绀,瀹氫箟涓涓彉閲廰鐨勫笺傚綋浣犳洿娣卞叆鐨勬椂鍊欙紝浣犲氨鍙互浣跨敤涓浜涗笓鐢ㄧ殑Python寮鍙戠幆澧冩潵杩涜浠g爜缂栧啓姣斿PyChatm鍜孞upyter銆傚笇鏈涘彲浠ュ府鍔╁埌浣犮
绛旓細鎵撳紑浣犵殑鏂囨湰缂栬緫鍣(鎴戞槸鐢‥mEditor锛屽綋鐒朵綘浣跨敤璁颁簨鏈佸啓瀛楁澘涔熼兘鍙互)锛岃緭鍏ython浠g爜锛淇濆瓨鎴*.py鏂囦欢锛岀劧鍚庡弻鍑昏繍琛屽畠灏卞彲浠ユ墽琛屼簡锛屽綋鐒跺墠鎻愪篃鏄繀椤婚厤缃郴缁烶ATH鍙橀噺銆俵 鍦ㄥ叾鎵鍦ㄧ洰褰曚笅寮鍚竴涓狢MD绐楀彛锛岃緭鍏ython *.py杩愯銆俵 鍦ㄤ唬鐮佺殑鏈鍚庡鍔濡備笅璇彞锛歳aw_input()鐒跺悗浣犲啀鍙屽嚮杩愯锛岀粨鏋滃氨浼...
绛旓細Python缂栫▼鍏ラ棬锛氳鎴戜滑鍒涘缓涓涓畝鍗曠殑绋嬪簭锛屽悕涓"hello.py"銆傝繖涓▼搴忕殑涓昏鍔熻兘鏄彁绀虹敤鎴疯緭鍏ヤ粬浠殑濮撳悕锛岀劧鍚庢墦鍗板嚭涓鍙ヤ釜鎬у寲鐨勯棶鍊欍備互涓嬫槸浠g爜瀹炵幇锛歱ython name=input("璇疯緭鍏ュ鍚:")print("浣犲ソ锛",name)杩娈典唬鐮棣栧厛閫氳繃`input()`鍑芥暟鑾峰彇鐢ㄦ埛杈撳叆鐨勫鍚嶏紝鐒跺悗浣跨敤`print()`鍑芥暟灏"浣犲ソ锛屽鍚...
绛旓細缃戦〉鍐呭濡備笅锛 python cgi 杈撳叆鐧诲綍瀵嗙爜锛 瀵嗐鐮侊細 login.py鏂囦欢鍐呭濡備笅锛!/usr/bin/python#coding:utf-8import cgiform = cgi.FieldStorage()ma = ""if 'ma
绛旓細Pycharm涓殑瀹忓姛鑳藉彲浠ュ府鍔╂垜浠揩閫熺殑鎻掑叆甯哥敤鐨浠g爜锛閭d箞濡備綍浣跨敤瀹忓姛鑳藉憿锛熶笅闈㈠皬缂栫粰澶у鍒嗕韩涓涓嬨1銆侀鍏堟墦寮Pycharm杞欢锛屾柊寤轰竴涓猵ython鏂囦欢锛濡備笅鍥炬墍绀 2銆佹帴涓嬫潵鐐瑰嚮椤堕儴鐨凟dit鑿滃崟锛屽湪涓嬫媺鑿滃崟涓夋嫨Macros涓嬮潰鐨凷tart Macro Recording閫夐」锛屽涓嬪浘鎵绀 3銆佺劧鍚庢垜浠紑濮嬪湪python鏂囦欢涓啓鍏ヤ竴浜涘父鐢...
绛旓細缂栧啓浠g爜锛氬彲浠ヤ娇鐢ㄤ换浣曟枃鏈紪杈戝櫒缂栧啓 Python 浠g爜銆備唬鐮佺殑鍏蜂綋鍐呭鏍规嵁绋嬪簭鐨勯渶姹傛潵鍐冲畾锛屽彲浠ュ寘鎷悇绉 Python 鍘熺敓璇硶銆佸唴缃嚱鏁般佺涓夋柟搴撶瓑绛夈傝繍琛岀▼搴忥細鍙互浣跨敤 Python 瑙i噴鍣ㄦ潵杩愯 Python 绋嬪簭銆傚湪缁堢鎴栧懡浠よ鐣岄潰杈撳叆 python 鏂囦欢鍚.py 鍗冲彲鎵ц绋嬪簭銆備笅闈㈡槸涓涓畝鍗曠殑绀轰緥绋嬪簭锛...
绛旓細閫python鐜浣跨敤Ctrl + Z杞 3. 鑴氭湰寮忚繍琛 涓ょ杩愯寮忚櫧绠渚块傚悎閲浠g爜鍙戦傚悎鏌ョ湅鍗曞彞鎴栧皯閲忓嚑鍙ヤ唬鐮佽繍琛岀粨鎴栬呴獙璇佹煇鍑芥暟璋冪敤鎭版伆鎴戝钩璋冭瘯銆侀獙璇佺▼搴忕敤寮忓紡鍙戝垯搴旇浣跨敤鐙珛鑴氭湰寮忚繍琛 鎵撴枃鏈紪杈戝櫒(鎴戠敤EmEditor浣跨敤璁颁簨鏈佸啓瀛楁澘閮)杈撳叆python浠g爜淇濆瓨*.py鏂囦欢鍙屽嚮杩愯鎵ц鍓嶆彁蹇呴』閰嶇疆绯荤粺PATH鍙橀噺 l...
绛旓細!/usr/bin/python# -*- coding:utf-8 -*-# @Time : 2018/6/14 9:30# @File : resistance.py"""璁$畻涓茶仈鍜屽苟鑱旂殑鐢甸樆"""def resistance(ar1, ar2): assert ar1 > 0 and ar2 > 0, u'闄ら潪瓒呭浣擄紝鍏朵粬鐢甸樆蹇呴』澶т簬0' if isinstance(ar1, (int, float)) and isinst...
绛旓細濡傛灉鐢╪umpy,杩欐槸瀹冨己椤癸紝鏁欑▼閲屾湁渚嬪瓙锛屽鍒朵竴涓 >>> from numpy import >>> a = arange(15).reshape(3, 5)>>> a array([[ 0, 1, 2, 3, 4],[ 5, 6, 7, 8, 9],[10, 11, 12, 13, 14]])杩欓噷杩樻湁涓暀绋嬶細http://hyry.dip.jp:8000/pydoc/numpy_intro....
绛旓細1.涓嬭浇Python瀹夎鍖呫2.瑙e帇Python瀹夎鍖呫倀ar -xzf Python-2.7.3.tgz3.鍦≒ython-2.7.3 鏍圭洰褰曚笅杩愯銆./configure#configure 鍛戒护鎵ц瀹屼箣鍚庯紝浼氱敓鎴愪竴涓 Makefile 鏂囦欢锛岃繖涓 Makefile涓昏鏄涓嬩竴姝ョ殑 make 鍛戒护鎵浣跨敤銆4.缂栬瘧Python婧愪唬鐮骞跺畨瑁呫俶ake&&make install5.瀹夎瀹屼箣鍚庯紝鎵цpython...