python鍐呯疆鏁版嵁缁撴瀯
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python鍐呯疆鏁版嵁缁撴瀯相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/ring' title='ring'>ring
- ==姣旇緝鐨勬槸鏁版嵁鍐呭锛屽鏋滄槸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/>瀵逛簬鍖呭惈澶嶆潅瀵硅薄鐨勫厓缁勶紝鍏舵寚鍚戝鏉傚璞$殑寮曠敤鍦板潃涓嶅彲鏇存敼锛屼絾澶嶆潅瀵硅薄鐨勬暟鎹唴瀹瑰彲鏇存敼
namedtuplefrom 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鍐呯疆鏁版嵁缁撴瀯的主要内容,如果未能解决你的问题,请参考以下文章
鏁版嵁缁撴瀯涓庣畻娉曪紙Python鐗堬級锛氱敤闃熷垪锛圦ueue锛夊鐞嗙害鐟熷か闂