上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 43 下一页
摘要: ``` #coding=utf-8 #python里面的字典,用{}来表示 book={'title':'python web development','year':2008} print book print 'year' in book print 'pub' in book print book.get('pub','N/A') book['pub']='Addison Wesley' ... 阅读全文
posted @ 2016-01-03 23:13 yufenghou 阅读(103) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 #元组是列表的近亲。列表用方括号,元组用小括号 #django配置文件大量用到元组 #注意,单个元素的元组要求在最后“必须”跟一个逗号。 a=("one","two") print a[0] b=("just-one") print b[0] c=("just-one",) print c[0] d="just-one", print d[0] ``` 阅读全文
posted @ 2016-01-03 22:34 yufenghou 阅读(120) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # 字符串指示符号 r表示raw u表示unicode mystring=u'this is unicode!--by' print mystring # 'raw'表示告诉解释器不要转换字符串任何字符 file=r'c:\temp\folder\robots.txt' print file # 另一个实用raw的地方是正则表达式 # 可以在'''内... 阅读全文
posted @ 2016-01-03 22:29 yufenghou 阅读(122) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # 列表推倒式子 data=[x+1 for x in range(10)] print data even_numbers=[x for x in range(10) if x%2 == 0] print even_numbers # 字符串 # 字符串是不可修改的,其大小也不能改变。任何试图改变字符串长度获释修改 # 内容的行为实际上是创造了一个心的修改... 阅读全文
posted @ 2016-01-03 22:15 yufenghou 阅读(122) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 #列表 book=['python','development',8] book.append(2008) print book book.insert(1,'web') print book print book[3:] print 'django' in book book.remove(8) book.pop(-1) print book print ... 阅读全文
posted @ 2016-01-03 11:22 yufenghou 阅读(100) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # python常用的列表list和字符串string # tuple元组,一个身有残疾的只读列表 s='python' print s[0] print s[-1] # 序列切片 print s[1:4] print s[3:] print s[:3] print s[:] # 字符串连接 连接+ 复制* 检查是否是成员 in 和 not in ... 阅读全文
posted @ 2016-01-03 11:13 yufenghou 阅读(102) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # python 有两个主要数据类型:int和float。根据Kiss原则,python只有一宗整数类型int。 print 3**3 print int('123') print int(45.67) print round(1.15,1) print float(10) print divmod(15,6) print ord('a') print ... 阅读全文
posted @ 2016-01-03 10:58 yufenghou 阅读(106) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # 任何等于0的数值被认为是False,所有非零的数字被认为True, # 空的容器为False,飞控容器酒味True。 download_complete=False print bool(download_complete) print bool(-1.23) print bool(0.0) print bool('') print bool([None... 阅读全文
posted @ 2016-01-02 22:07 yufenghou 阅读(99) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # 没有++ 和--其他的都一样 foo=1 show_output=True if show_output and foo==1: print 'pyhont and %s are number %d' % ('django',foo) # python 只有一些@符号和下划线符号,只有干净和容易阅读的代码才能避免混乱。 ``` 阅读全文
posted @ 2016-01-02 21:51 yufenghou 阅读(135) 评论(0) 推荐(0)
摘要: ``` #coding=utf-8 # python没有花括号。我们用对齐来代替括号:通常是四个空格(任意数目的空格货tab也都可以) # python 注释用 # # python不需要像其他语言那样需要首先声明一个特定的类型, # python是一门动态语言 foo='bar' print foo foo=1 print foo ``` 阅读全文
posted @ 2016-01-02 21:33 yufenghou 阅读(141) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 43 下一页