1茄螃、print()輸出
a\%輸出
a=1
b=1
c=2
print("%d+%d=%d"%(a,b,c))
name="小明"
age=13
print("%s今年%d歲"%(name,age))
pi=3.141592653
print("pi保留小數(shù)點(diǎn)后三位為%4.3f"%pi)#字段寬4缝驳,精度3
print("pi保留小數(shù)點(diǎn)后三位為 %.*f" % (3,pi)) #用*從后面的元組中讀取字段寬度或精度
for i in range(0,3):
? ? print(i, end = '' )
b\format實(shí)現(xiàn)輸出
print("{} {}".format("hello", "world") )
print("{0} {1}".format("hello", "world") ) # 設(shè)置指定位置
print("{1} {0} {1}".format("hello", "world")? )# 設(shè)置指定位置
print("{:.3f}".format(3.1415926))
print("{:+.3f}".format(3.1415926))#帶符號(hào)保留兩位小數(shù)
print("{:.0f}".format(3.1415926))#不保留小數(shù)
print("{:.2%}".format(0.25))
print("{:.2e}".format(100000000))
print("{:,}".format(100000))
測(cè)試結(jié)果:
3.142
+3.142
3
25.00%
1.00e+08
100,000
2sys argv 實(shí)現(xiàn)文件存儲(chǔ)(存儲(chǔ)位置加上>)
import sys
import random
n = int(sys.argv[1])
for i in range(0, n):
? ? print(random.randint(0,100))
print(sys.argv[0])
print(sys.argv[1])
3、文件讀入
filename = r'C:\Users\asus\Desktop\Python_Test\data2.txt'
file = open(filename, 'a')#追加寫入
file.write('1,2,3,4\n5,6,7,8')
file.close()
更多細(xì)節(jié)參考python的輸入
4归苍、pandas實(shí)現(xiàn)
filename = r'C:\Users\asus\Desktop\Python_Test\data3.xls' #絕對(duì)路徑
df = pd.read_excel(filename,header = None)
df.iloc[0,0] = 100
print(df.iloc[0,0])
df.to_csv(r'.\data.csv')#相對(duì)路徑
補(bǔ)充:
1用狱、tab鍵查找要存儲(chǔ)的文件格式
2、iloc選取文件讀取范圍
3拼弃、(r'.\data.csv')==('./data.csv')
參考博客:https://blog.csdn.net/sinat_29957455/article/details/79059436
4.numpy文件存儲(chǔ)
參考博客:https://blog.csdn.net/runner668/article/details/80360828