V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Explorare
V2EX  ›  Python

About Python

  •  
  •   Explorare · 2015-02-09 20:08:31 +08:00 · 3966 次点击
    这是一个创建于 3377 天前的主题,其中的信息可能已经有所发展或是发生改变。
    months = [
        'jabuary',
        'february',
        'march',
        'april',
        'may',
        'june',
        'july',
        'august',
        'september',
        'october',
        'november',
        'december'
        ]
    
    
    #为何使用反斜杠可以换行
    #这段代码的意思是什么?这还是序列吗?
    #_||_
    #\  /
    # \/
    endings = ['st','nd','rd'] + 17*['th'] \
            + ['st','nd','rd'] + 7*['th'] \
            + ['st']
    # /\
    #/  \  
    
    
    year = raw_input('year:')
    month = raw_input('month:')
    day = raw_input('day:')
    
    
    month_num = int(month)
    day_num = int(day)
    
    
    month_name = months[month_num - 1]
    ordinal = day + endings[day_num-1]
    
    
    print month_name+'  '+ordinal+', '+year
    

    问题已经在代码中注释了,版本是2.7.9
    另,我听说python中没有数组,这是真的吗?

    22 条回复    2015-02-10 02:08:47 +08:00
    Kilerd
        1
    Kilerd  
       2015-02-09 20:17:30 +08:00   ❤️ 1
    数组可以这样实现

    a={'a':'1','b':'2'}
    这个叫dict 是吧?

    Python 的三种常用的数据类型

    a=['aa','bb','cc']

    a=('aa','bb','cc')
    icodesign
        2
    icodesign  
       2015-02-09 20:19:42 +08:00
    哥,能把代码整理整理好吗
    Explorare
        3
    Explorare  
    OP
       2015-02-09 20:21:02 +08:00
    @icodesign 抱歉啊,本站支持Markdown么?
    Explorare
        4
    Explorare  
    OP
       2015-02-09 20:21:31 +08:00
    @Kilerd 多谢帮助( ゚∀。)
    happywowwow
        5
    happywowwow  
       2015-02-09 20:22:02 +08:00
    看了看 想了想
    LZ究竟是怎么编辑的markdown
    看完发现应该是python里的注释吧。。。。。。

    顺便反斜杠换行在C语言里也是可以的
    只能说,就是这样了......
    chenxytw
        6
    chenxytw  
       2015-02-09 20:23:31 +08:00   ❤️ 1
    没看懂你的代码在说什么;
    python 有数组的, 但是只适用于 C 的那些基本类型
    import array, 具体你可以 help 一下
    不过, 一般在python里面用 list 来当数组用~
    icodesign
        7
    icodesign  
       2015-02-09 20:29:18 +08:00
    @Explorare 右侧「创建新主题」不是可以吗
    Explorare
        8
    Explorare  
    OP
       2015-02-09 20:45:30 +08:00
    @icodesign 看到了,下次会注意的,多谢提醒。
    aaaa007cn
        9
    aaaa007cn  
       2015-02-09 21:10:32 +08:00   ❤️ 1
    读 PEP8 去
    https://www.python.org/dev/peps/pep-0008/
    主要是 Maximum Line Length 这段
    jint
        10
    jint  
       2015-02-09 21:38:07 +08:00   ❤️ 1
    代码尾部的反斜杠,有个专门的名字: 续行标志。
    lance6716
        11
    lance6716  
       2015-02-09 23:23:42 +08:00 via Android
    (ゝ∀・) 大丧尸
    正在看Python文档的路过
    Explorare
        12
    Explorare  
    OP
       2015-02-09 23:27:02 +08:00
    @lance6716 你在丧失什么啦⊂彡☆))∀`)当心我碎你饼干哦( ゚∀。)
    Livid
        13
    Livid  
    MOD
       2015-02-09 23:28:18 +08:00   ❤️ 2
    @Explorare 支持的。

    但是你发代码的时候没有加上

    ```python
    ```

    已经为你加上了。
    icedx
        14
    icedx  
       2015-02-09 23:45:08 +08:00   ❤️ 1
    反斜杠换行是很多语言的特性 不只Python有
    endings = ['st','nd','rd'] + 17*['th'] \
    + ['st','nd','rd'] + 7*['th'] \
    + ['st']
    是生成一个序列 等同于endings = ['st','nd','rd'] + 17*['th'] + ['st','nd','rd'] + 7*['th'] + ['st']
    目的是生成一个长度为 3+17+3+7+1=31的序列用来给日期加符号
    kingname
        15
    kingname  
       2015-02-09 23:53:34 +08:00 via iPad   ❤️ 2
    举几个例子你就明白了。在Python 中,有以下特性:
    ['aa','bb'] +['cc','dd']的结果是['aa','bb','cc','dd']

    3*['th']的结果是['th','th','th']前面的数字是几,就重复多少遍。

    python 里面的"列表"相当于C的数组。
    Sunyanzi
        16
    Sunyanzi  
       2015-02-10 00:33:02 +08:00
    @lance6716 夭寿啦!A 岛的丧失都跑到 V2 上来啦!(´゚Д゚`)
    Explorare
        17
    Explorare  
    OP
       2015-02-10 01:20:20 +08:00
    @Sunyanzi 询问版(沉)-->V2作死版( ゚∀。)
    Explorare
        18
    Explorare  
    OP
       2015-02-10 01:20:48 +08:00
    @Livid 多谢协助
    Explorare
        19
    Explorare  
    OP
       2015-02-10 01:22:06 +08:00
    @icedx 多谢解释,李福菊
    icedx
        20
    icedx  
       2015-02-10 01:51:50 +08:00
    @Explorare 李福菊?
    icedx
        21
    icedx  
       2015-02-10 01:52:53 +08:00
    @Explorare !活捉D8 丧尸一只!
    Explorare
        22
    Explorare  
    OP
       2015-02-10 02:08:47 +08:00
    @icedx My Little poi~( ゚∀。)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1315 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 75ms · UTC 23:32 · PVG 07:32 · LAX 16:32 · JFK 19:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.