每天一个小Error

Strip()

sText = '\'Programming\'itself is the best way to learn programming.\n\t-Nobody'
print(sText.strip())
sText = '\'Programming\'itself is the best way to learn programming.\n\t-Nobody\tand end here.'
print(sText.strip())
输出
'Programming'itself is the best way to learn programming.
        -Nobody
'Programming'itself is the best way to learn programming.
        -Nobody and end here.

切片(倒序)

nums = [0,1,2,3,4,5,6,7,8,9,10,11,12]
print(nums[-1:3:-2])
输出
[12, 10, 8, 6, 4]

创建空字典

#创建空字典
a = set([])
b = {}
c = {'This','is','not','set','!'}
for x in (a,b,c):
    print(type(x))
print(a)
输出
<class 'set'>
<class 'dict'>
<class 'set'>
set()

read(),readline(),readlines()

  • 不要忘记指针的问题
BUG
#文件读写
#f.read():从文件中读出全部内容并以字符串形式(文本模式)返回
#f.read(5):从文件读出五个字符
#f.readline() -->str
#f.readlines() -->list
#f.write()写入数据
#f.writeline()写入一行
f = open('letter.txt','r',encoding = 'UTF-8')
sflines = f.read()
flst = f.readlines()
sfline = f.readline()
print(sflines)
print(sfline)
print(flst)
输出
When I stand before thee at the day's end, thou shalt see my scars and know that I had my wounds and also my healing.
当日子完了,我站在你的面前, 你将看到我的疤痕,知道我曾经受伤,也曾经痊愈。

[]
解决:seek()
#fileObject.seek(offset[, whence])
#offset -- 开始的偏移量,也就是代表需要移动偏移的字节数
#whence:可选,默认值为 0。给offset参数一个定义,表示要从哪个位置开始偏移;
# 0代表从文件开头开始算起,1代表从当前位置开始算起,2代表从文件末尾算起。
f = open('letter.txt','r',encoding = 'UTF-8')
sflines = f.read()
f.seek(0,0)
flst = f.readlines()
f.seek(0,0)
sfline = f.readline()
print(sflines)
print(sfline)
print(flst)
When I stand before thee at the day's end, thou shalt see my scars and know that I had my wounds and also my healing.
当日子完了,我站在你的面前, 你将看到我的疤痕,知道我曾经受伤,也曾经痊愈。
When I stand before thee at the day's end, thou shalt see my scars and know that I had my wounds and also my healing.

["When I stand before thee at the day's end, thou shalt see my scars and know that I had my wounds and also my healing.\n", '当日子完了,我站在你的面前, 你将看到我的疤痕,知
道我曾经受伤,也曾经痊愈。']

列表转换为字符串

#列表转换为字符串
l = ['a','b']
print(str(l))
print(''.join(l))
输出
['a', 'b']#相当于'['a','b']'
ab

组合数comb()出错

from scipy.special import comb
n1 = comb(64,32)#近似解
n2 = comb(64,32,exact = True)#精确解
print('{:.0f}'.format(n1))
print(n2)
输出
1832624140942590464
1832624140942590534
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值