摘要:        
在Python中写文件也是得先打开文件的。1 file=open(r'E:\temp\test.txt','a')2 file.write('append to file')3 file.close()第一行使用追加模式打开文件,第二行则将内容写入文件,第三行关闭文件。除了write方法外,还有wr...    阅读全文
posted @ 2014-09-27 17:19
h82258652
阅读(238)
评论(0)
推荐(0)
        
            
        
        
摘要:        
在Python中,读取文件使用open函数1 file=open(r'E:\temp\test.txt','r')2 var = file.read()3 print(var)4 file.close()第一行打开E:\temp\test.txt文件,注意字符串开头使用了r,r表明字符串内的内容不转...    阅读全文
posted @ 2014-09-27 17:12
h82258652
阅读(227)
评论(0)
推荐(0)
        
            
        
        
摘要:        
在Python中,输出使用print函数,之前用过了。输入的话,则使用input函数。1 var = input()2 print('you input is' + var)输入haha则将输出you input is haha。可见input的作用与C#中的Console.ReadLine方法一样...    阅读全文
posted @ 2014-09-27 16:58
h82258652
阅读(210)
评论(0)
推荐(0)
        
            
        
        
摘要:        
Python是一门面向对象语言,那么作为面向对象的特征——类也是有的。值得注意的是Python中一切皆对象,并不像C#中为了性能考虑,int这些在Python中也是对象。(C#中int是结构体)如何定义一个类:1 class Person:2 pass使用class关键字,上面定义了一个Pe...    阅读全文
posted @ 2014-09-27 16:46
h82258652
阅读(348)
评论(0)
推荐(0)
        
            
        
        
摘要:        
在Python中定义函数的时候,可以使用参数默认值的方式定义函数例子:1 def welcome(who,state='is',action='talking'):2 print(who,state,action)调用函数:1 welcome('Tom')输出Tom is talking1 ...    阅读全文
posted @ 2014-09-27 14:11
h82258652
阅读(177)
评论(0)
推荐(0)
        
            
        
        
摘要:        
先定义一个最基本的函数作为例子:1 def Print(msg):2 print(msg)函数名为Print,参数有一个,为msg,函数体调用print系统函数,输出msg。接下来就是可变参数,这个特性是比较特殊的,像C#中的params,但又有所不同。例子1:1 def PrintTupl...    阅读全文
posted @ 2014-09-27 13:55
h82258652
阅读(298)
评论(0)
推荐(0)
        
            
        
        
摘要:        
例子:1 i = 12 while i < 10:3 print(i)4 i+=15 else:6 print('finish')输出1至9和finish在while语句中同样支持for语句所支持的continue、break和else    阅读全文
posted @ 2014-09-27 13:28
h82258652
阅读(200)
评论(0)
推荐(0)
        
            
        
        
摘要:        
Python中循环可以使用for语句来实现1 list = ['Tom','Lucy','Mary']2 for name in list:3 print(name)则将会依次输出Tom Lucy Mary另外Python还支持continue和break关键字,用法与C#相同。比较有特点的...    阅读全文
posted @ 2014-09-27 13:14
h82258652
阅读(391)
评论(0)
推荐(0)
        
            
        
        
摘要:        
Python的分支语句比较简单,只有if、else、elif三个关键字,也就是说,Python没有switch语句,而且,Python中并没有?:这个三目运算符。例子:1 age = 182 if age < 18:3 print('too young')4 elif age == 18:5...    阅读全文
posted @ 2014-09-27 01:09
h82258652
阅读(509)
评论(0)
推荐(0)
        

 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号