欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python常用函數(shù)與用法示例

 更新時(shí)間:2019年07月02日 11:34:42   作者:火紅橘子  
這篇文章主要介紹了python常用函數(shù)與用法,涉及Python文件讀取、刪除、數(shù)值計(jì)算、打印等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了python常用函數(shù)與用法。分享給大家供大家參考,具體如下:

自定義函數(shù)實(shí)例

# 定義一個(gè)函數(shù)
def printme( str ):
  "打印任何傳入的字符串"
  print str;
  return;
# 使用這個(gè)函數(shù)
printme("chtml.cn");

運(yùn)行結(jié)果:

chtml.cn

刪除一個(gè)文件函數(shù)實(shí)例

def dellFile(pathFile):
  import os
  filename = pathFile
  if os.path.exist(filename):
  os.remove(filename)
  print filename
  return;

python打印金子塔

def printPyramid(level):
  for i in range(level):
    print ' ' * (level-i-1) + '*' * (2*i+1)
printPyramid(5)

運(yùn)行結(jié)果:

    *
   ***
  *****
 *******
*********

python寫九九乘法表

print '\n9x9 Table\n'
for i in range(1, 10) :
  for j in range(1, i+1) :
    print j, 'x', i, '=', j*i, '\t',
    # print '%d x %d = %d\t' %(j, i, j*i),
  print '\n'
print '\nDone!'

運(yùn)行結(jié)果:


9x9 Table

1 x 1 = 1  


1 x 2 = 2  
2 x 2 = 4  


1 x 3 = 3  
2 x 3 = 6  
3 x 3 = 9  


1 x 4 = 4  
2 x 4 = 8  
3 x 4 = 12  
4 x 4 = 16  


1 x 5 = 5  
2 x 5 = 10  
3 x 5 = 15  
4 x 5 = 20  
5 x 5 = 25  


1 x 6 = 6  
2 x 6 = 12  
3 x 6 = 18  
4 x 6 = 24  
5 x 6 = 30  
6 x 6 = 36  


1 x 7 = 7  
2 x 7 = 14  
3 x 7 = 21  
4 x 7 = 28  
5 x 7 = 35  
6 x 7 = 42  
7 x 7 = 49  


1 x 8 = 8  
2 x 8 = 16  
3 x 8 = 24  
4 x 8 = 32  
5 x 8 = 40  
6 x 8 = 48  
7 x 8 = 56  
8 x 8 = 64  


1 x 9 = 9  
2 x 9 = 18  
3 x 9 = 27  
4 x 9 = 36  
5 x 9 = 45  
6 x 9 = 54  
7 x 9 = 63  
8 x 9 = 72  
9 x 9 = 81  

Done!

讀取文件內(nèi)容

all_the_text = open('thefile.txt').read( )

讀取文件夾里的所有文件

all_the_data = open('abinfile','rb').read( )

關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python函數(shù)使用技巧總結(jié)》、《Python面向?qū)ο蟪绦蛟O(shè)計(jì)入門與進(jìn)階教程》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python字符串操作技巧匯總》、《Python編碼操作技巧總結(jié)》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論