python鍐呯疆鏁版嵁缁撴瀯

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python鍐呯疆鏁版嵁缁撴瀯相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/ring' title='ring'>ring   鏁版嵁   sub   鍑虹幇   max   绱㈠紩   鏍囬   涓句緥   copy   

娣辨祬鎷疯礉

  • ==姣旇緝鐨勬槸鏁版嵁鍐呭锛屽鏋滄槸True鎰忎箟涓哄唴瀹圭浉鍚岋紝寮曠敤骞朵笉鍚?/li>
  • =鎿嶄綔鎵ц鍚庯紝鍓嶅悗涓や釜鍏冪礌鐨勫紩鐢ㄥ湴鍧€鐩稿悓
    娴呮嫹璐?/strong>

copy() -> List

  • 杩斿洖涓€涓柊鐨勫垪琛?/li>
  • 寮曠敤绫诲瀷鍙嫹璐濆紩鐢ㄥ湴鍧€

娣辨嫹璐?/strong>

  • 瀹屽叏鎷疯礉銆傚寘鎷紩鐢ㄧ被鍨?br/>from copy import deepcopy
    lst2=deepcopy.(lst)

闅忔満鏁?/strong>

import random

randint(a, b)

  • 杩斿洖[a, b]涔嬮棿鐨勬暣鏁?闂尯闂?br/>choice(seq)

  • 浠庨潪绌哄簭鍒楃殑鍏冪礌涓殢鏈烘寫閫変竴涓厓绱狅紝姣斿
    random.choice(range(10))
    锛屼粠0鍒?涓殢鏈烘寫閫変竴涓暣鏁般€?br/>random.choice([1,3,5,7])
    randrange ([start,] stop [,step])

  • 浠庢寚瀹氳寖鍥村唴锛屾寜鎸囧畾鍩烘暟閫掑鐨勯泦鍚堜腑鑾峰彇涓€涓殢鏈烘暟锛屽熀鏁扮己鐪佸€间负1銆?br/>random.randrange(1,7,2)
  • 鍓嶉棴鍚庡紑
    random.shuffle(list) ->None

  • 灏卞湴鎵撲贡鍒楄〃鍏冪礌
    sample(population, k)

  • 浠庢牱鏈┖闂存垨鎬讳綋锛堝簭鍒楁垨鑰呴泦鍚堢被鍨嬶級涓殢鏈哄彇鍑簁涓笉鍚岀殑鍏冪礌锛岃繑鍥炰竴涓柊鐨勫垪琛?br/>鍏冪粍

  • 鏈夊簭鐨勫厓绱犻泦鍚?br/>鍒濆鍖栵細

    t=tuple()
    t=()
    t=(1,)

  • 鍏冪粍鏌ヨ涓庡垪琛ㄧ被浼?/li>
  • 鍏冪粍鍏冪礌涓嶅彲淇敼
    娉ㄦ剰锛?br/>瀵逛簬鍖呭惈澶嶆潅瀵硅薄鐨勫厓缁勶紝鍏舵寚鍚戝鏉傚璞$殑寮曠敤鍦板潃涓嶅彲鏇存敼锛屼絾澶嶆潅瀵硅薄鐨勬暟鎹唴瀹瑰彲鏇存敼
    namedtuple

    from collections import namedtuple
    Point=namedtuple(鈥楶oint鈥?[鈥榵鈥? 鈥榶鈥榏)
    #Point=namedtuple(鈥楶oint鈥?鈥榵 y鈥? 绗簩绉嶅啓娉?br/>p1=Point(11锛?2)
    print(p1.x,p1.y)
    閮ㄥ垎婧愮爜锛?/p>

    if isinstance(field_names, str):
    field_names = field_names.replace(鈥?鈥? 鈥?鈥?.split()
    field_names = list(map(str, field_names))
    typename = str(typename)
    瀛楃涓?/p>

瀛楃涓插璞′笉鍙彉
浣跨敤鈥?鈥樸€?quot; "銆佲€樷€樷€?鈥樷€樷€樺寘鍥寸殑瀛楃搴忓垪
涓句緥
s1 = 鈥榮tring鈥?br/>s2 = "string2"
s3 = 鈥樷€樷€榯his鈥榮 a "String" 鈥樷€樷€?br/>s4 = 鈥榟ello magedu.com鈥?br/>s5 = r"hello magedu.com"
s6 = 鈥榗:windows t鈥?br/>s7 = R"c:windows t"
s8 = 鈥榗:windows t鈥?br/>sql = """select * from user where name=鈥榯om鈥?"""
瀛楃涓叉敮鎸佷娇鐢ㄧ储寮曡闂?br/>鍙凯浠?br/>join杩炴帴

"string".join(iterable) -> str
灏嗗彲杩唬瀵硅薄鐨勬瘡涓€涓厓绱犵敤string杩炴帴璧锋潵
杩斿洖涓€涓柊瀛楃涓插璞?br/>+

杩炴帴涓や釜瀛楃涓?br/>杩斿洖涓€涓柊瀛楃涓插璞?br/>瀛楃涓插垎鍓?/p>

split(sep=None, maxsplit=-1) -> list of strings
浠庡乏鑷冲彸
sep 鎸囧畾鍒嗗壊瀛楃涓诧紝缂虹渷鐨勬儏鍐典笅绌虹櫧瀛楃涓蹭綔涓哄垎闅旂
maxsplit 鎸囧畾鍒嗗壊鐨勬鏁帮紝-1 琛ㄧず閬嶅巻鏁翠釜瀛楃涓?br/>rsplit(sep=None, maxsplit=-1) -> list of strings
浠庡彸鍚戝乏
splitlines([keepends]) -> list of strings
鎸夌収琛屾潵鍒囧垎瀛楃涓?br/>keepends 鎸囩殑鏄槸鍚︿繚鐣欒鍒嗛殧绗?br/>琛屽垎闅旂鍖呮嫭 銆乗r 銆乗r绛?br/>partition(sep) -> (head, sep, tail)
浠庡乏鑷冲彸锛岄亣鍒板垎闅旂灏辨妸瀛楃涓插垎鍓叉垚涓ら儴鍒嗭紝杩斿洖澶淬€佸垎闅旂銆佸熬涓夐儴鍒嗙殑涓夊厓缁勶紱
濡傛灉娌℃湁鎵惧埌鍒嗛殧绗︼紝灏辫繑鍥炲ご銆?涓┖鍏冪礌鐨勪笁鍏冪粍
sep 鍒嗗壊瀛楃涓诧紝蹇呴』鎸囧畾
瀛楃涓插ぇ灏忓啓

upper()
鍏ㄥぇ鍐?br/>lower()
鍏ㄥ皬鍐?br/>澶у皬鍐欙紝鍋氬垽鏂殑鏃跺€欑敤
swapcase()
浜や簰澶у皬鍐?br/>瀛楃涓叉帓鐗?/p>

title() -> str
鏍囬鐨勬瘡涓崟璇嶉兘澶у啓
capitalize() -> str
棣栦釜鍗曡瘝澶у啓
center(width[, fillchar]) -> str
width 鎵撳嵃瀹藉害
fillchar 濉厖鐨勫瓧绗?br/>zfill(width) -> str
width 鎵撳嵃瀹藉害锛屽眳鍙筹紝宸﹁竟鐢?濉厖
ljust(width[, fillchar]) -> str
宸﹀榻?br/>rjust(width[, fillchar]) -> str
鍙冲榻?br/>瀛楃涓蹭慨鏀?/p>

replace(old, new[, count]) -> str
瀛楃涓蹭腑鎵惧埌鍖归厤鏇挎崲涓烘柊瀛愪覆锛岃繑鍥炴柊瀛楃涓?br/>count琛ㄧず鏇挎崲鍑犳锛屼笉鎸囧畾灏辨槸鍏ㄩ儴鏇挎崲
strip([chars]) -> str
浠庡瓧绗︿覆涓ょ鍘婚櫎鎸囧畾鐨勫瓧绗﹂泦chars涓殑鎵€鏈夊瓧绗?br/>濡傛灉chars娌℃湁鎸囧畾锛屽幓闄や袱绔殑绌虹櫧瀛楃
lstrip([chars]) -> str
浠庡乏寮€濮?br/>rstrip([chars]) -> str
浠庡彸寮€濮?br/>find(sub[, start[, end]]) -> int
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屼粠宸﹁嚦鍙筹紝鏌ユ壘瀛愪覆sub銆傛壘鍒拌繑鍥炵储寮曪紝娌℃壘鍒拌繑鍥?1
rfind(sub[, start[, end]]) -> int
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屼粠鍙宠嚦宸︼紝鏌ユ壘瀛愪覆sub銆傛壘鍒拌繑鍥炵储寮曪紝娌℃壘鍒拌繑鍥?1
index(sub[, start[, end]]) -> int
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屼粠宸﹁嚦鍙筹紝鏌ユ壘瀛愪覆sub銆傛壘鍒拌繑鍥炵储寮曪紝娌℃壘鍒版姏鍑哄紓甯竀alueError
rindex(sub[, start[, end]]) -> int
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屼粠宸﹁嚦鍙筹紝鏌ユ壘瀛愪覆sub銆傛壘鍒拌繑鍥炵储寮曪紝娌℃壘鍒版姏鍑哄紓甯竀alueError
count(sub[, start[, end]]) -> int
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屼粠宸﹁嚦鍙筹紝缁熻瀛愪覆sub鍑虹幇鐨勬鏁?br/>瀛楃涓插垽鏂?/p>

endswith(suffix[, start[, end]]) -> bool
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屽瓧绗︿覆鏄惁鏄痵uffix缁撳熬
startswith(prefix[, start[, end]]) -> bool
鍦ㄦ寚瀹氱殑鍖洪棿[start, end)锛屽瓧绗︿覆鏄惁鏄痯refix寮€澶?br/>is绯诲垪

isalnum() -> bool
鏄惁鏄瓧姣嶅拰鏁板瓧缁勬垚
isalpha()
鏄惁鏄瓧姣?br/>isdecimal()
鏄惁鍙寘鍚崄杩涘埗鏁板瓧
isdigit()
鏄惁鍏ㄩ儴鏁板瓧(0~9)
isidentifier()
鏄笉鏄瓧姣嶅拰涓嬪垝绾垮紑澶达紝鍏朵粬閮芥槸瀛楁瘝銆佹暟瀛椼€佷笅鍒掔嚎
islower()
鏄惁閮芥槸灏忓啓
isupper()
鏄惁鍏ㄩ儴澶у啓
isspace()
鏄惁鍙寘鍚┖鐧藉瓧绗?/p>

以上是关于python鍐呯疆鏁版嵁缁撴瀯的主要内容,如果未能解决你的问题,请参考以下文章

鏁版嵁缁撴瀯-C璇█瀹炵幇-閾炬爤

鏁版嵁缁撴瀯鐭ヨ瘑妗嗘灦

鏁版嵁缁撴瀯涓庣畻娉曪紙Python鐗堬級锛氱敤闃熷垪锛圦ueue锛夊鐞嗙害鐟熷か闂

鏁版嵁缁撴瀯锛堜竴锛夌嚎鎬ц〃寰幆閾捐〃鐩稿叧琛ュ厖

鏁版嵁缁撴瀯瀹為獙涔嬫爤涓庨槦鍒楀崄涓€锛歳efresh鐨勫仠杞﹀満

鏁版嵁缁撴瀯瀹為獙涔嬮摼琛ㄥ洓锛氭湁搴忛摼琛ㄧ殑褰掑苟