文件操作等练习代码

1.练习代码

'''

fileName = input('请输入文件名称:')
contentList = '我是你妈妈'
fileOpen = open(fileName,'a+')
fileOpen.write(contentList)
fileOpen.seek(0)
for line in fileOpen.readlines():
     print(line)

import numpy as np
x = [
    [1,2,3,4],
    [4,3,2,1],
    [5,6,7,8],
    [9,8,7,6]
]
print(type(x))
print(np.array(x).transpose())
print(type(np.array(x).transpose()))
print(np.array(x).T)
y = np.mat(x)
print(y.transpose())
print(type(y))
z = np.matrix(x)
print(z.T)
print(type(z))
x = np.array(range(10))
print(x)
print(x[x>4])'''
import numpy as np
import matplotlib.pyplot as plt

'''
fig = plt.figure()          #首先要定义一个figure对象,可以理解成一张画板
ax1 = fig.add_subplot(221)  #添加轴,可以理解为建立平面直角坐标系
ax1.set(xlim = [0,100],ylim = [-1,1],title = 'an example axes',ylabel = "金钱/t",xlabel = '时间/s')

#plt.show()

ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)
ax4.set(xlim = [0,100],ylim = [-1,1],title = 'you mother fucker',ylabel = 'y-axis',xlabel = 'x-ax')

x = np.linspace(0,100,10000)
y = np.cos(x)

ax1.plot(x,y,'-',linewidth = '2',markersize = '12',color = 'green')
ax4.plot(x,y,'--')
plt.show()

plt.plot(x,y,ls = '-',label = 'plot figure',lw = 2)
plt.legend()
plt.show()
fig = plt.figure()
axes = plt.subplots(norows = 2,ncols = 2)
x = np.linspace(0,np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)
y_constant = x * 0 + 5
axes[0,1].set(title = '11111111',color = 'red')
axes[1,1].set(title = '44444444',color = 'green')

plt.show()'''
import numpy as np
import matplotlib.pyplot as plt

#首先创建对象
fig = plt.figure(figsize=(8,4),facecolor='red')
fig.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python文件操作练习题是指通过Python代码文件进行读取、写入、重命名等操作练习题目。其包括创建文件、写入内容、读取文件内容、重命名文件等。 举个例子,假设有以下练习题: 题目:请编写一个Python程序,要求用户输入文件名和字符串,将字符串写入到指定的文件。 解答:可以使用Python的open函数打开文件,然后使用write方法将字符串写入文件。可以参考以下代码: ```python filename = input("请输入文件名:") content = input("请输入字符串:") with open(filename, "w") as file: file.write(content) ``` 这段代码,用户需要输入文件名和字符串,然后使用`open`函数打开文件,指定模式为"w"表示写入模式。然后使用`write`方法将字符串写入文件。 这是一个简单的Python文件操作练习题的答案,通过这个练习可以增加对Python文件操作的熟悉程度。当然,还有很多其他的练习题目,涉及到文件的读取、重命名、删除等操作,可以根据需要选择不同的练习题目进行练习。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Python经典基础习题(文件文件操作)](https://blog.csdn.net/AQIANKE/article/details/126265497)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Python函数文件练习题汇总](https://blog.csdn.net/qq_44034384/article/details/107600201)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值