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!
  • 相关阅读:
    怎么在Vue项目中使用Element组件
    vue-cli 基本使用
    C++ delete指针以后应赋值为NULL
    C++ noexcept异常说明及其使用
    Qt 设置comboBox里面的字体颜色
    Qt 获取可用串口
    Qt 寻找可用串口
    荧光显微镜简介
    荧光滤光片简介
    消色差、半复消色差、复消色差的区别
  • 原文地址:https://www.cnblogs.com/scajy/p/9785628.html
Copyright © 2011-2022 走看看