c语言可以像python一样直接加减字符串么? 比如 print("#"+"good"+"#"*7 用c语言或者python将文件中特定字符串后面的数字相加
python\u4e0d\u652f\u6301\u50cfc\u4e00\u6837\u7684\u5b57\u7b26\u5f53assic\u8fd0\u7b97\u5417\uff1f\u6bd4\u5982 \u2018a\u2019+ 32\u6211\u4e5f\u521a\u5f00\u59cb\u5b66\uff0c\u76ee\u6d4b\u4f1a\u8bc6\u522b\u6210\u5b57\u7b26\u4e32\uff1f
\u4ee3\u7801\u5e94\u8be5\u4e0d\u96be\u5427\u3002\u65e2\u7136\u7528\u722c\u866b\u722c\u4e0b\u6765\u4e86\uff0c\u4e3a\u4ec0\u4e48\u722c\u53d6\u6570\u636e\u7684\u65f6\u5019\u6ca1\u505a\u5904\u7406\u5462\u3002
\u4e4b\u524d\u7528\u8fc7Scrapy\u722c\u866b\u6846\u67b6\uff0c\u633a\u597d\u7528\u7684\uff0c\u4f60\u53ef\u7814\u7a76\u4e0b\u3002
\u4ee3\u7801\uff1a
#!coding=utf-8import osimport reimport random# \u83b7\u53d6\u5f53\u524d\u76ee\u5f55\u6587\u4ef6\u5217\u8868def getNum(): flist = os.listdir(os.getcwd()) # \u904d\u5386\u6587\u4ef6 for f in flist: if f != os.path.basename(__file__): with open(f, 'r') as fn: text = fn.read() num = re.findall(r'\u8bc4\u8bba\u4eba\u6570\uff1a(\d+)', text) print f, num# \u6587\u4ef6\u5199\u5165\u6d4b\u8bd5def test(): for i in range(10): with open('%d.txt' % i, 'w') as f: f.write('\u6587\u4ef6\uff1a%d\n\u6bcf\u5bb6\u9910\u9986\u662f\u4e00\u4e2a\u6587\u4ef6\uff0c\u7edf\u8ba1\u8bc4\u8bba\u6570\uff0c\u6c42\u8bfb\u53d6\u6bcf\u4e2a\u6587\u4ef6\u4e2d \u201c\u8bc4\u8bba\u4eba\u6570\uff1a%d\u201d \u4e2d \u768460\u5e76\u76f8\u52a0\uff0c\u6c42\u5177\u4f53\u7a0b\u5e8f\uff0c60\u662f\u4e2a\u4f8b\u5b50' % (i, random.randint(1, 200))) print u'\u6587\u4ef6\u5199\u5165\u5b8c\u6bd5'if __name__ == '__main__': # test() getNum()\u4ee3\u7801\u57fa\u672c\u7b26\u5408\u8981\u6c42\uff0c\u4f46\u5065\u58ee\u6027\u6709\u4e9b\u5dee\u3002\u4f60\u81ea\u5df1\u7528\u7684\u65f6\u5019\u4fee\u6539\u5427
\u6d4b\u8bd5\u7ed3\u679c\uff1a
C:\Python27\python.exe D:/11/c.py\u6587\u4ef6\u5199\u5165\u5b8c\u6bd50.txt ['131']1.txt ['181']2.txt ['56']3.txt ['119']4.txt ['18']5.txt ['103']6.txt ['88']7.txt ['115']8.txt ['160']9.txt ['136']Process finished with exit code 0
不可以,字符串没有加减运算,需用函数实现字符串拼接
不能如果是输出,使用printf("%s %s %s \r\n", a, b, c) 很方便的了
~
~
~
~
绛旓細鏈夊緢澶氱浉浼肩殑涓滆タ锛屾帶鍒惰鍙ョ殑鐞嗚鐩稿悓锛屽彧鏄叿浣撳啓娉曟湁宸埆锛屽彉閲忓父閲忔暟鎹被鍨嬬悊璁烘у樊涓嶅锛屼唬鐮佹т篃宸埆涓嶅ぇ锛屼絾鏄c璇█鐨勬暟鎹被鍨嬶紝鏁扮粍绫诲瀷鍜岀粨鏋勭畝鍗曟槑浜嗭紝浠g爜楹荤儲锛python绾补鏄簲鐢ㄥ眰娆★紝涓C璇█浠庡紑鍙戣搴﹀簲鐢ㄨ搴﹂兘鏈夊緢澶х殑涓嶅悓銆傚鏋滃悓鏃跺湪瀛涓Python鏈濂戒笉瑕侊紝杩欐牱浼氭垚涓轰竴閿呯播锛屽緢闅惧垎娓呫
绛旓細涓銆佽瑷绫诲瀷涓嶅悓C璇█鏄瘮杈冨彜鑰佺殑璇█,骞舵病鏈夊お澶氶珮绾ц瑷鐨勭壒鎬,鍦ㄨ瑷绫诲瀷涓婁粬灞炰簬缂栬瘧鍨嬭瑷,浣曚负缂栬瘧鍨嬭瑷,缂栬瘧鍨嬭瑷灏辨槸缁忚繃浜嗚蒋浠剁殑缂栬瘧鍚,鐢熸垚鏈哄櫒鐮,鐒跺悗鍐嶇敱璁$畻鏈烘搷浣滅郴缁熷幓杩愯,浠栫殑浼樼偣灏辨槸鎵ц閫熷害寰堝揩,鍥犱负浠栨槸鏈鎺ヨ繎璁$畻鏈哄簳灞傜殑璇█,鍜岃绠楁満浜や簰鐨勬椂鍊,鏁堢巼鏄緢楂樼殑,浠栫殑缂虹偣灏辨槸鐢变簬渚濊禆搴曞眰...
绛旓細1銆丳ython鏄竴绉嶉潰鍚戝璞$殑瑙i噴鍨嬭瑷锛岄氳繃缂╄繘鏉ヨ〃绀鸿鍙ヤ綋锛屽湪Python涓姣忎竴鏉¤鍙ョ粨灏惧悗娌℃湁鍒嗗彿锛2銆丆鏄竴绉嶉潰鍚戣繃绋嬬殑缂栬瘧鍨嬭瑷锛岄氳繃鈥渰}鈥濇潵琛ㄧず璇彞浣擄紝C璇█涓姣忎竴鏉¤鍙ラ渶浠ヨ嫳鏂囧垎鍙风粨灏俱Python鍜孋璇█閮芥槸涓绉嶉珮绾х紪绋嬭瑷锛屽畠浠箣闂存湁鐩镐技涔嬪锛屼篃鏈変笉灏戝樊寮傘備笅闈㈡湰绡囨枃绔犲氨...
绛旓細1銆佽瑷绫诲瀷锛Python鏄竴绉嶅熀浜庤В閲婂櫒鐨勮瑷锛岃В閲婂櫒浼氶愯璇诲彇浠g爜锛屽皢Python缂栬瘧涓哄瓧鑺傜爜锛岀劧鍚庣敱澶у瀷C绋嬪簭瑙i噴;C鏄竴绉嶇紪璇戣瑷锛屽畬鏁寸殑婧愪唬鐮佸皢鐩存帴缂栬瘧涓烘満鍣ㄤ唬鐮侊紝鐢盋PU鐩存帴鎵ц銆2銆佸唴瀛樼鐞嗭細Python浣跨敤鑷姩鍨冨溇鏀堕泦鍣ㄨ繘琛屽唴瀛樼鐞;C璇█涓绋嬪簭鍛樺繀椤昏嚜宸辫繘琛屽唴瀛樼鐞嗐3銆佸簲鐢細Python鏄竴闂ㄩ氱敤缂栫▼...
绛旓細1. 璇硶锛歅ython璇硶鐩稿绠鍗锛屾槗浜庡涔犲拰鐞嗚В锛岃孋璇█鍒欐瘮杈冪箒鐞愶紝闇瑕佹洿澶氱殑瀛︿範鍜岀粌涔犮2. 鍔熻兘锛歅ython鏄竴绉嶈В閲婃ц瑷锛屽叿鏈夊姩鎬佺被鍨嬪拰鑷姩鍐呭瓨绠$悊绛夌壒鎬э紝鍙敤浜庡紑鍙戝悇绉嶇被鍨嬬殑搴旂敤绋嬪簭锛屽Web搴旂敤绋嬪簭銆佹暟鎹垎鏋愩佹満鍣ㄥ涔犵瓑銆傝孋璇█鍒欐槸涓绉嶇紪璇戝瀷璇█锛屽叿鏈夋洿楂樼殑鎬ц兘鍜屾洿骞挎硾鐨勭‖浠舵敮鎸侊紝鍙...
绛旓細python鍜宑 鐨勫尯鍒涓: 1銆佽娉:Python鐨璇硶鐩稿绠鍗曘傝C璇█鐨勮娉曠浉瀵瑰鏉傘 2銆佸唴瀛樼鐞:Python鏄嚜鍔ㄥ唴瀛樼鐞,鑰孋璇█闇瑕佹墜鍔ㄧ鐞嗗唴瀛樸 3銆佸簲鐢ㄩ鍩:Python琚簲鐢ㄤ簬Web寮鍙戙佹暟鎹垎鏋愮瓑棰嗗煙銆傝孋璇█涓昏鐢ㄤ簬搴曞眰寮鍙戙 4銆佹墽琛岄熷害:C璇█閫氬父姣擯ython鏇村揩,鍥犱负C璇█鏄紪璇戝瀷璇█,鑰孭ython鏄В閲婂瀷璇█銆
绛旓細Python鏄竴绉嶉氱敤缂栫▼璇█锛屼竴涓鑼冨紡锛屼富瑕佹敮鎸侀潰鍚戝璞$紪绋嬶紝绋嬪簭缂栫▼锛屽嚱鏁扮紪绋嬨侰鏄粨鏋勫寲缂栫▼璇█锛屽厑璁镐娇鐢ㄥ嚱鏁帮紝閫夋嫨锛坕f/else绛夛級锛岃凯浠o紙寰幆锛夛紝鏈涓昏鐨勭敤閫斿氨鏄郴缁熷簳灞傜殑搴旂敤銆3銆佸鏉傚害 Python涓涓嶉渶瑕佸0鏄庡彉閲忕被鍨嬨C璇█涓蹇呴』澹版槑鍙橀噺绫诲瀷銆4銆佹祴璇曞拰璋冭瘯闅惧害 Python鐩稿鍏朵粬璇█鑰岃█鏄...
绛旓細棣栧厛锛C璇█鏄竴绉嶉潤鎬佺被鍨嬬殑缂栬瘧鍨嬭瑷銆傝繖鎰忓懗鐫鍦ㄧ紪鍐欎唬鐮佷箣鍓嶏紝浣犻渶瑕佹槑纭瘡涓彉閲忕殑绫诲瀷锛屽int銆乫loat銆乧har绛夈備竴鏃﹁瀹氾紝绫诲瀷灏变笉鑳芥敼鍙樸傝孭ython鏄竴绉嶅姩鎬佺被鍨嬬殑瑙i噴鍨嬭瑷銆傚湪Python涓锛屼綘涓嶉渶瑕侀鍏堝0鏄庡彉閲忕殑绫诲瀷锛岀被鍨嬬殑纭畾鏄湪杩愯鏃惰繘琛岀殑銆傜紪璇戞柟寮 C璇█闇瑕佸厛缂栬瘧鎴愭満鍣ㄨ兘鐩存帴鎵ц鐨...
绛旓細C璇█鏄紪璇戝瀷璇█锛岀粡杩囩紪璇戝悗锛岀敓鎴愭満鍣ㄧ爜锛岀劧鍚庡啀杩愯锛屾墽琛岄熷害蹇紝涓嶈兘璺ㄥ钩鍙帮紝涓鑸敤浜庢搷浣滅郴缁燂紝椹卞姩绛夊簳灞傚紑鍙戙Python鏄紪璇戝瀷杩樻槸瑙i噴鍨嬭繖涓晫闄愬苟涓嶆槑鏄撅紝浣嗗ぇ鑷翠笂鍙互鐞嗚В涓鸿В閲婂瀷璇█锛屾墽琛岄熷害鎱紝鐢变簬Python铏氭嫙鏈猴紝Python鏄彲浠ヨ法骞冲彴鐨勶紝Python楂樺害闆嗘垚閫傚悎浜庤蒋浠剁殑蹇熷紑鍙戙傛荤粨锛欳璇█姣...
绛旓細Python鏄敱C璇█瀹炵幇锛孋璇█鏄紪璇戝瀷璇█銆傝瑷绫诲瀷锛歅ython鏄竴绉嶅熀浜庤В閲婂櫒鐨勮瑷锛岃В閲婂櫒浼氶愯璇诲彇浠g爜锛涢鍏堝皢Python缂栬瘧涓哄瓧鑺傜爜锛岀劧鍚庣敱澶у瀷C绋嬪簭瑙i噴锛汣鏄竴绉嶇紪璇戣瑷锛屽畬鏁寸殑婧愪唬鐮佸皢鐩存帴缂栬瘧涓烘満鍣ㄤ唬鐮侊紝鐢盋PU鐩存帴鎵ц鐏溅澶存爣棰樹吉鍘熷垱php婧愮爜锛涘唴瀛樼鐞嗭細Python浣跨敤鑷姩鍨冨溇鏀堕泦鍣ㄨ繘琛屽唴瀛樼鐞嗭紱鍦–...