美文网首页
python 的输出总结

python 的输出总结

作者: 阿媛门前的一棵葡萄树 | 来源:发表于2019-07-11 21:01 被阅读0次

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保留小数点后三位为%4.3f"%pi)#字段宽4,精度3

print("pi保留小数点后三位为 %.*f" % (3,pi)) #用*从后面的元组中读取字段宽度或精度

for i in range(0,3):

    print(i, end = '' )

b\format实现输出

print("{} {}".format("hello", "world") )

print("{0} {1}".format("hello", "world") ) # 设置指定位置

print("{1} {0} {1}".format("hello", "world")  )# 设置指定位置

print("{:.3f}".format(3.1415926))

print("{:+.3f}".format(3.1415926))#带符号保留两位小数

print("{:.0f}".format(3.1415926))#不保留小数

print("{:.2%}".format(0.25))

print("{:.2e}".format(100000000))

print("{:,}".format(100000))

测试结果:

3.142

+3.142

3

25.00%

1.00e+08

100,000


2sys argv 实现文件存储(存储位置加上>)

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()

更多细节参考python的输入


4、pandas实现

filename = r'C:\Users\asus\Desktop\Python_Test\data3.xls' #绝对路径

df = pd.read_excel(filename,header = None)

df.iloc[0,0] = 100

print(df.iloc[0,0])

df.to_csv(r'.\data.csv')#相对路径

补充:

1、tab键查找要存储的文件格式

2、iloc选取文件读取范围

3、(r'.\data.csv')==('./data.csv')

参考博客:https://blog.csdn.net/sinat_29957455/article/details/79059436


4.numpy文件存储

参考博客:https://blog.csdn.net/runner668/article/details/80360828

相关文章

  • python 的输出总结

    1、print()输出 a\%输出 a=1 b=1 c=2 print("%d+%d=%d"%(a,b,c)) n...

  • Python基础

    最近开始在自学Python,所以在学习的时候也一边总结一些知识点 Python的输出 Python的输出和C语言类...

  • Python面向对象进行封装处理文件属性

    Python面向对象进行封装处理文件属性 输出结果 image.png 总结

  • Python语法总结

    Python 简明语法总结 !!! 只针对有经验开发人员 简单输入输出 输出print 10 , '十' 输入na...

  • python-print函数的使用

    1.格式化输出 看看《Python基础编程》中对格式化输出的总结: %字符:标记转换说明符的开始 转换标志:-表示...

  • Python输出函数print()总结

    一、print()函数概述 print() 方法用于打印输出,是python中最常见的一个函数。 该函数的语法如下...

  • Python学习笔记1

    Python注释 Python变量 Python运算符 Python输入输出 输入函数 输出函数(3.x) ...

  • Python的输出和输入

    Python的输出 常见的Python输出是使用print内建函数,或者输出到文件,或者输出到数据库,本文的输出主...

  • 变量和简单数据类型

    变量 输出:Hello Python world! 输出:Hello Python Crash Course wo...

  • test

    python 输出python版本信息

网友评论

      本文标题:python 的输出总结

      本文链接:https://www.haomeiwen.com/subject/rahjkctx.html