如何使用python格式化输出方程图?

时间:2015-01-07 02:30:01

标签: python loops

我是初学者所以我认为我不需要使用任何复杂的东西。 基本上我必须print y=x^+3使用格式化输出x=0x=4,我不知道如何。

根据我到目前为止所学到的,我应该使用格式化输出,循环和可变宽度输出来执行此操作。

有谁知道怎么做?非常感谢你。

2 个答案:

答案 0 :(得分:1)

查看模块matplotlib,它是为了在python中绘制视觉效果。我希望这有点帮助。

答案 1 :(得分:0)

  

可能我只需打印该行,有没有办法做到这一点?

以下是一个例子:

for x in range(3, 7):
    y = x + 2
    print "With x equal to {},  y = {}".format(x, y)

--output:--
With x equal to 3,  y = 5
With x equal to 4,  y = 6
With x equal to 5,  y = 7
With x equal to 6,  y = 8

使用format()方法的参数代替' {}'顺序,从左到右依次排列。您也可以自己指定订单:

                                       +---+-----------------+
for x in range(3, 7):                  |   |                 |
    y = x + 2                          V   V                 |
    print "Here are some numbers: {0} {1} {1} {0}".format(x, y)
                                   ^           ^          | 
                                   |           |          |  
                                   +-----------+----------+  
--output:--
Here are some numbers: 3 5 5 3
Here are some numbers: 4 6 6 4
Here are some numbers: 5 7 7 5
Here are some numbers: 6 8 8 6

点击此处查看更多示例:

https://docs.python.org/3/library/string.html#format-examples