Executing multi-line statements in python in interactive mode

后端 未结 2 712
我在风中等你
我在风中等你 2021-01-27 15:37

I am new to the world of Python, and this is my first program in Python. I come from the world of R so this is a bit unintuitive to me.

When I execute

         


        
2条回答
  •  有刺的猬
    2021-01-27 16:08

    In the Python 2.7.10 console, doing the following: importing math and random, getting a random number, and taking a square root of a number outputs as such:

    >>> import math
    >>> import random
    >>> random.random()
    0.52350453737542
    >>> math.sqrt(85)
    9.219544457292887 
    

    If you want both values to be printed contiguously, you can write multiple-line statements separated by the semi-colon operator:

    >>> import math
    >>> import random
    >>> random.random(); math.sqrt(85)
    0.9031053664569808
    9.219544457292887
    

提交回复
热议问题