python语法学习练习1

python语法学习练习1

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** IDLE 1.2.1 >>> ================================ RESTART ================================ >>> s ='abc' >>> for a in s: print a ; SyntaxError: invalid syntax >>> print s abc >>> for a in a:print a Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> for a in a:print a NameError: name 'a' is not defined >>> for a in s:print a a b c >>> str='akakak' >>> str=str.replace('k',' 8') >>> print str a 8a 8a 8 >>> str='akakak'str=str.replace('k',' 8')str='akakak' SyntaxError: invalid syntax >>> str='akakak' >>> str=str.replace('k','8') >>> print str a8a8a8 >>> str='a,hello' >>> print str.find('hello') 2 >>> str='a,b,c,d' >>> strlist=str.split(',') >>> for value in strlist: print value a b c d >>> def getclass(txt_s): str_array=txt_s.split('#') return str_array[0] >>> print getclass('chen3#4.6men') chen3 >>> print getclass('鍩庨晣寤烘柊鍖?#锛? 鎬婚潰绉細38.42浜?) SyntaxError: EOL while scanning single-quoted string >>> print getclass('鍩庨晣寤烘柊鍖?#锛?) 鍩庨晣寤烘柊鍖? >>> t=getclass('鍩庨晣寤烘柊鍖?#锛?) >>> print t 鍩庨晣寤烘柊鍖? >>> for a in t:print a ? ? ? ? ? ? ? ? ? ? 1 >>> num=-1 >>> print num -1 >>> for a in t: if(a>=0 && a<=9): SyntaxError: invalid syntax >>> for a in t: if(a>=0 and a<=9): print a >>> for a int t: SyntaxError: invalid syntax >>> for a in t: if(a==1) print a SyntaxError: invalid syntax >>> for a in t: if(a=='1'): print a 1 >>> dkbh='' >>> for a in t: if(a=='1'): if(dkbh==''): dkbh=a else SyntaxError: invalid syntax >>> i=1 >>> while i<10: i+=1 if i%2>0: continue print i 2 4 6 8 10 >>> print i 10 >>> i=1 >>> while 1: print i i+=1 if(i>10): break 1 2 3 4 5 6 7 8 9 10 >>> def getclass(txt_s): dkbh='' for a in t: if(a=='1' or a=='2' or a=='3' or a=='4'): if(dkbh==''): dkbh=a else: dkbh+=a return dkbh File "<pyshell#68>", line 2 dkbh='' ^ IndentationError: expected an indented block >>> str='a,b,c,d' >>> strlist=str.split(',') >>> for value in strlist: print value a b c d >>> def myadd(a=1,b=100): result=0 i=a while i<=b: result+=i i+=1 return result >>> print myadd(1,10) 55 >>> print myadd() 5050 >>> print myadd(50) 3825 >>> def getclass(txt_s): dkbh='' for a in txt_s: if(a=='1' or a=='2' or a=='3' or a=='4'): if(dkbh==''): dkbh=a else: dkbh+=a return dkbh File "<pyshell#85>", line 1 def getclass(txt_s): ^ IndentationError: unexpected indent >>> ================================ RESTART ================================ >>> a=1 >>> a.isnumeric() Traceback (most recent call last): File "<pyshell#87>", line 1, in <module> a.isnumeric() AttributeError: 'int' object has no attribute 'isnumeric' >>> a.isnumeric Traceback (most recent call last): File "<pyshell#88>", line 1, in <module> a.isnumeric AttributeError: 'int' object has no attribute 'isnumeric' >>> txt_s='sfsfsd3#2.6' >>> print txt_s sfsfsd3#2.6 >>> t=txt_s[0:txt_s.find('#')] >>> print t sfsfsd3 >>> print t.isdigit() False >>> for a in t: print a.isdigit() False False False False False False True >>> print t sfsfsd3 >>> dkbh='' >>> for a in t: if(a.isdigit()==true): if(dkbh==''): dkbh=a else SyntaxError: invalid syntax >>> for a in t: if(a.isdigit()==true): if(dkbh==''): dkbh=a else: dkbh+=a Traceback (most recent call last): File "<pyshell#105>", line 2, in <module> if(a.isdigit()==true): NameError: name 'true' is not defined >>> for a in t: if(a.isdigit()==True): if(dkbh==''): dkbh=a else: dkbh+=a >>> print dkbh 3 >>>

getclass5(!RefName!)

def getclass5(txt_s):
         t=txt_s
         t=t[0:t.find('#')]
         dkbh=''
         for a in t:
             if(a.isdigit()==True):
                 if(dkbh==''):
                      dkbh=a
                 else:
                      dkbh+=a
         return dkbh     

--the--end--

---2012-03-09---

转载于:https://www.cnblogs.com/sqlite3/archive/2012/03/09/2566734.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值