Python×Ö·û´®²Ù×÷
#Python×Ö·û´®²Ù×÷
''
'1.¸´ÖÆ×Ö·û´®'
''
#strcpy(
sStr1,
sStr2)
sStr1 =
'strcpy'
sStr2 =
sStr1
sStr1 =
'strcpy2'
print
sStr2
''
'2.Á¬½Ó×Ö·û´®'
''
#strcat(
sStr1,
sStr2)
sStr1 =
'strcat'
sStr2 =
'append'
sStr1 +
=
sStr2
print
sStr1
''
'3.²éÕÒ×Ö·û'
''
#strchr(
sStr1,
sStr2)
sStr1 =
'strchr'
sStr2 =
'r'
nPos =
sStr1.
index(
sStr2)
print
nPos
''
'4.±È½Ï×Ö·û´®'
''
#strcmp(
sStr1,
sStr2)
sStr1 =
'strchr'
sStr2 =
'strch'
print
cmp(
sStr1,
sStr2)
''
'5.ɨÃè×Ö·û´®ÊÇ·ñ°üº¬Ö¸¶¨µÄ×Ö·û'
''
#strspn(
sStr1,
sStr2)
sStr1 =
'12345678'
sStr2 =
'456'
#sStr1 and
chars both in
sStr1 and
sStr2
print
len(
sStr1 and
sStr2)
''
'6.×Ö·û´®³¤¶È'
''
#strlen(
sStr1)
sStr1 =
'strlen'
print
len(
sStr1)
''
'7.½«×Ö·û´®ÖеÄСд×Ö·ûת»»Îª´óд×Ö·û'
''
#strlwr(
sStr1)
sStr1 =
'JCstrlwr'
sStr1 =
sStr1.
upper(
)
print
sStr1
''
'8.×·¼ÓÖ¸¶¨³¤¶ÈµÄ×Ö·û´®'
''
#strncat(
sStr1,
sStr2,
n)
sStr1 =
'12345'
sStr2 =
'abcdef'
n =
3
sStr1 +
=
sStr2[
0:
n]
print
sStr1
''
'9.×Ö·û´®Ö¸¶¨³¤¶È±È½Ï'
''
#strncmp(
sStr1,
sStr2,
n)
sStr1 =
'12345'
sStr2 =
'123bc'
n =
3
print
cmp(
sStr1[
0:
n]
,
sStr2[
0:
n]
)
''
'10.¸´ÖÆÖ¸¶¨³¤¶ÈµÄ×Ö·û'
''
#strncpy(
sStr1,
sStr2,
n)
sStr1 =
''
sStr2 =
'12345'
n =
3
sStr1 =
sStr2[
0:
n]
print
sStr1
''
'11.×Ö·û´®±È½Ï£¬²»Çø·Ö´óСд'
''
#stricmp(
sStr1,
sStr2)
sStr1 =
'abcefg'
sStr2 =
'ABCEFG'
print
cmp(
sStr1.
upper(
)
,
sStr2.
upper(
)
)
''
'12.½«×Ö·û´®Ç°n¸ö×Ö·ûÌ滻Ϊָ¶¨µÄ×Ö·û'
''
#strnset(
sStr1,
ch,
n)
sStr1 =
'12345'
ch =
'r'
n =
3
sStr1 =
n *
ch +
sStr1[
3:
]
print
sStr1
''
'13.ɨÃè×Ö·û´®'
''
#strpbrk(
sStr1,
sStr2)
sStr1 =
'cekjgdklab'
sStr2 =
'gka'
nPos =
-
1
for
c in
sStr1:
if
c in
sStr2:
nPos =
sStr1.
index(
c)
Ïà¹ØÎĵµ£º
ÔÚPythonÖпÉÒÔ°Ñproperty¶¯Ì¬µÄ°ó¶¨µÄobjectµÄ¼Ì³ÐÀàÖУ¬²¢ÇÒ¿ÉÒÔ¶¨Òå´øÓвÎÊýµÄgetºÍset·½·¨¡£
±ÈÈ磬ÎÒÃǶ¨ÒåÁËÈ«¾Ö±äÁ¿g£¬È»ºóͨ¹ýÁ½¸ö·½·¨À´´æÈ¡gµÄÄÚÈÝ
def get_g(self):
return g
def set_g(self, _g):
global g
g = _g
¶¨ÒåÒ»¸öobjectµÄ¼Ì³ ......
PEP 0263
Defining Python Source Code Encodings
Python will default to ASCII as standard encoding if no other
encoding hints are given.
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, suc ......
#!/Library/Frameworks/Python.framework/Versions/2.5/bin/python
# encoding: utf-8
import sys, time
import thread
SLEEP_TIME = 0.0001
def run_benchmark(n, m):
# print(">> Python 2.5.1, stackless 3.1b3 here (N=%d, M=%d)!\n" % (n, m))
lock ......
Python-String-Function
×Ö·û´®ÖÐ×Ö·û´óСдµÄ±ä»»£º
* S.lower() #Сд
* S.upper() #´óд
* S.swapcase() #´óСд»¥»»
* S.capitalize() #Ê××Öĸ´óд
&n ......
ÖÐÎļò½é
¡¡¡¡Python (·¢Òô:[ 'paiθ(?)n; (US) 'paiθ?n ]n.òþÉߣ¬¾ÞÉß )£¬ÊÇÒ»ÖÖÃæÏò¶ÔÏóµÄ½âÊÍÐԵļÆËã»ú³ÌÐòÉè¼ÆÓïÑÔ£¬Ò²ÊÇÒ»ÖÖ¹¦ÄÜÇ¿´ó¶øÍêÉƵÄͨÓÃÐÍÓïÑÔ£¬ÒѾ¾ßÓÐÊ®¶àÄêµÄ·¢Õ¹ÀúÊ·£¬³ÉÊìÇÒÎȶ¨¡£Python ¾ßÓнű¾ÓïÑÔÖÐ×î·á¸»ºÍÇ¿´óµÄÀà¿â£¬×ãÒÔÖ§³Ö¾ø´ó¶àÊýÈÕ³£Ó¦Óá£ËüµÄÃû×ÖÀ´Ô´ÓÚÒ»¸öϲ¾ç,Ò²Ðí×î³õÉè ......