小编use*_*538的帖子

如何检查字符串是否只包含python中给定集合的字符

我有一个用户输入的多项式,我只想使用它,如果它只有字符串中的字符1234567890^-+x.

如何在不使用外部包的情况下检查是否存在?我只想使用内置的Python 2.5函数.

我正在编写一个可以在任何Mac上运行而无需外部软件包的程序.

python string python-2.5

6
推荐指数
3
解决办法
1万
查看次数

检查float是否是Python中的整数

我在画布上绘制图形并插入画布文本对象以标记x和y轴间隔.

这是我的代码.

def update():
    scalex1=graph.create_text(356,355-87,text='%.1f'%scalex,anchor=NW)
    scalex2=graph.create_text(412,355-87,text='%.1f'% (scalex*2),anchor=NW)
    scalex3=graph.create_text(471,355-87,text='%.1f'%(scalex*3),anchor=NW)
    scalex4=graph.create_text(532,355-87,text='%.1f'%(scalex*4),anchor=NW)

    scalenx1=graph.create_text(255-23,355-87,text='%.1f'%(scalex*-1),anchor=NW)
    scalenx2=graph.create_text(195-25,355-87,text='%.1f'% (scalex*-2),anchor=NW)
    scalenx3=graph.create_text(135-25,355-87,text='%.1f'%(scalex*-3),anchor=NW)
    scalenx4=graph.create_text(66-18,355-87,text='%.1f'%(scalex*-4),anchor=NW)


    scaley1=graph.create_text(326,234,text='%.1f'%scaley,anchor=NW)
    scaley2=graph.create_text(326,174,text='%.1f'% (scaley*2),anchor=NW)
    scaley3=graph.create_text(326,114,text='%.1f'%(scaley*3),anchor=NW)
    scaley4=graph.create_text(326,54,text='%.1f'%(scaley*4),anchor=NW)

    scaleny1=graph.create_text(326,354,text='%.1f'%(scaley*-1),anchor=NW)
    scaleny2=graph.create_text(326,414,text='%.1f'%(scaley*-2),anchor=NW)
    scaleny3=graph.create_text(326,474,text='%.1f'%(scaley*-3),anchor=NW)
    scaleny4=graph.create_text(326,534,text='%.1f'%(scaley*-4),anchor=NW)
Run Code Online (Sandbox Code Playgroud)

这将根据输入的比例绘制所有间隔.

x2=float(x1.get())
y2=float(y1.get())

scalex=5.0*(x2/25.0)
scaley=5.0*(y2/25.0)
Run Code Online (Sandbox Code Playgroud)

这将确定x和y轴上每个刻度的比例,并将其乘以5以获得每五个刻度的值.有25个刻度,所以我将输入/ 25分开.

我想显示值,但它们都是浮点数.我想告诉他们没有.00s(我有%.1F将其限制在1位小数),如果他们是真正的整数,并告诉他们最多2位小数,如果他们实际上是浮动,不附带.00s整数.有没有办法做到这一点?

编辑1:例如,比例为25,因此每个刻度为1.第五个刻度将为-10.0,-5.0,5.0,10.0,15.0等.我希望它显示10,5,15等,但如果它是.5,1.0,1.5,2.0我想保留小数除了真正的整数,如1.0和2.0,它将成为1和2.

谢谢!

python floating-point int

2
推荐指数
1
解决办法
191
查看次数

标签 统计

python ×2

floating-point ×1

int ×1

python-2.5 ×1

string ×1