Code practice Simple File read-write string array processing list Dictionary

Source: Internet
Author: User

func.py #-*-CODING:GBK-*-"" "in Python the default is ANSI encoding format to use Chinese need to explicitly specify coded array into dynamic array and static array dynamic array can dynamically add element static array cannot change data structure def definition func tion def func:return void type function definition def funcshow (): print "Void type Func Test" returnfuncshow (); "" Import stringimport func #引入另一个模块import sys# test output Print R "This was a line with \ n" Print 5**5print u "abcde:%s---g%s"% ("Yuedo Ngwei ", [' One ', ' II ', ' three ') ') ' For I in range (0, 5): Print Ielse:passprint" string "+ hex #输出print __name__# array Test A = [1,2,[1,2,[1,2,[1,2,[2,3,4,5]]]]]print a[2][2][2][2]ii = 0arr = [1,23,4]arr.append] Arr.reverse () #reserve Reverse output print arrarr.append ([2,3,4,5,6,7]), Arr.sort ();p rint arr; arrfixed= (1,2,3,4,5) #固定数组print Arrfixedarrmultidimensional = [I for I in range (3,10), 1,[]]print arrmultidimensionalarrmultidimensional[2].append (" Test ") Print arrmultidimensional# dictionary operation dic={" Key1 ": 1," Key2 ": 2};p rint dicprint dic.keys () print dic.get (" Key1 ") print dic ["Key1"]print sys.path# function called Test Func. Funcshow (); #FuncShow ();p rint "Result:" +str (Func.add(100,200)) Print __doc__; #返回注释print nonesystest.py#-*-coding:gbk-*-"" "System Call" "" Import Osfilehandle=open ("C:\\1.txt", "W") Filehandle.write (" I am a programmer ") Filehandle.close () Filehandle=open (" C:\\1.txt "," R ") print Filehandle.read () object-oriented python#-*-CODING:GBK-*-" The object-oriented Python self is the default implicit delivery "" "Class Data:i=0 def GetData (self) that shows delivery of C + + Java, etc.: Return self.i def __ini        T__ (self,a,b,c): self.a=a;        Self.b=b;    Self.c=c; def ShowData (self): print "a=%d,b=%d,c=%d"% (SELF.A,SELF.B,SELF.C) Returnobj=data (all in all) print obj. GetData () obj. ShowData ()

Code practice Simple File read-write string array processing list Dictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.