人生的意义就是思考其意义分享 http://blog.sciencenet.cn/u/qianlivan 天体物理工作者,家乡云南昆明。

博文

程序(脚本)设计的一些要素

已有 2966 次阅读 2013-10-28 11:06 |个人分类:知识|系统分类:科研笔记| 程序, 要素

1. 变量赋值、查看变量值
Linux bash
      [xxx@xxx]$ x=1
      [xxx@xxx]\$ echo \$x
      1
Dos
      D:\> set /a x=1
      D:\> echo %x%
      1
python
      >>> x=1
      >>> print(x)
2. 注释
Linux bash
        # comments will not take effect
Dos
        rem comments will not take effect
        :: comments will not take effect
python
        # comments will not take effect
        """
           comments will not take effect
        """
3. 循环(数字风格)
Linux bash
        for ((i=0; i<10; ++i))
        do
              echo $i
        done 
Dos
        for /l %i in (1,1,9) do @echo %i
python
        for i in range(1,11):
             print(i)

4. 判断
Linux bash
        if ((x<2))
        then echo good
        else echo bad
        fi
Dos
        if /i %x% lss 2 (echo good) else echo bad
python
        if x<2:
           print('good')
        else:
           print('bad')




https://blog.sciencenet.cn/blog-117333-736733.html

上一篇:我用过的DOS命令
下一篇:星座边界坐标
收藏 IP: 159.226.171.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-2 18:17

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部