python.py #!/usr/bin/env python #coding:UTF-8 print('this liucx,s first python code!') if True: print 'ture' else: print 'false' ''' This is an annotation test Hey, let's learn something See if it's fun. ''' #raw_input('\n\nPress the enter key to exit.') import sys; x='runb'; sys.stdout.write(x+'\t\n') #Newline output a='1'; b='2'; # newline output print a; print b; # output without wrapping print a,; print b,; # output without wrapping print a,b; #print sys.argv[1]; #The following is an if statement with input under myself, find the right c=1;#sys.argv[1]; if c=='1': print 'yes'; else : print 'A parameter needs to be output'; #I'm very happy, the above is written correctly, I didn't read the documentation. continue. . . . . . def testFunction(param): print(param+10); return; #below is a for loop fruits = ['banana', 'apple', 'mango'] for f in fruits: if(f=='mango'): break; print(f); print("End of for loop"); ''' String manipulation ''' str="abcdefghijklmnopwxyzxyz"; str2="1234567890"; print(str[1]); print(str2[2:4]); #Method operation testFunction(20); #Object operation import object o1=object.add(100); print(o1); #Object operation end---------------------------- #keyboard input in1=raw_input("Please enter a sentence:"); print in1; in2=input("Please enter an expression:");#You can enter an expression print in2; #Open file file object = open(file_name [, access_mode][, buffering]) f1=open("object.py"); print "File name: ",f1.name; print "Is it closed",f1.closed; print "Access mode:",f1.mode; print f1.read(); f1.close(); print "Is it closed",f1.closed; try: f2=open("testFile","a"); f2.write("This is a test content"); except IOerror: print "Error opening the file, maybe the file does not exist"; else: print "File written successfully"; f2.close();
object.pyc def add(a): return a+2;