How to use the -c flag in python

前端 未结 2 495
礼貌的吻别
礼貌的吻别 2020-12-31 05:38

I noticed in the python doc that there is a -c flag. Here is what python doc says:

Execute the Python code in command. comma

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 06:07

    Easiest example

    python -c "print 'example'"
    

    It is useful whenever your program has a single line of code, for example, list comprehensions, etc.

    Another example can be

    python -c "a='example';print a"
    

    As you can see, multiple statements are separated by ;

提交回复
热议问题