zoukankan      html  css  js  c++  java
  • python-基础

    1. hello world程序
      在linux下创建一个文件叫hello.py,并输入
      

    print("Hello World!")

      然后执行命令:python hello.py,输出

    [root@test-1 python]# vim hello.py
    [root@test-1 python]# python hello.py 
    Hello World!

      指定解释器

      上一步中执行python hello.py时,明确的指出hello.py脚本由python解释器来执行。
      如果想要类似于执行shell脚本一样执行python脚本,例如:./hello.py,那么就需要在hello.py文件的头部指定解释器,如下:

    [root@test-1 python]# cat hello.py 
    #!/usr/bin/env python #指定解释器
    print("Hello World!")
    [root@test-1 python]# chmod +x hello.py 
    [root@test-1 python]# /python/hello.py 
    Hello World!

      如此一来,执行:./hello.py 或/python/hello.py

      ps:执行前需给予hello.py执行权限,chmod 755 hello.py
    在交互器中执行
      除了把程序写在文件里,还可以直接调用python自带的交互器运行代码,
      

    [root@test-1 python]# python
    Python 2.7.5 (default, Apr 11 2018, 07:36:10) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print("hello world!")
    hello world!
  • 相关阅读:
    图论概况
    [NOI2006]最大获利
    Dining
    [USACO5.3]校园网Network of Schools 缩点
    I Hate It
    [USACO06JAN]牛的舞会The Cow Prom Tarjan
    爱在心中
    [HAOI2006]受欢迎的牛
    泥泞的道路
    上白泽慧音
  • 原文地址:https://www.cnblogs.com/scajy/p/9785628.html
Copyright © 2011-2022 走看看