Python学习笔记【1】

来源:互联网 发布:three.js 实现宇宙 编辑:程序博客网 时间:2024/05/07 03:34

1、%r和%s的区别

(1)stackflow 上面的一个解答

(2)

x = "There are %d types of people." %10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s." % (binary,do_not)print xprint yprint "I said: %r." % xprint "I also said: '%s'." % yprint "I also said: %s." %yprint "I also said: '%r'." %yprint "I also said: %r." %yhilarious = Falsejoke_evaluation = "Isn't that joke so funny?!%r"print joke_evaluation % hilariousw = "This is the left side of..."e = "a string with a right side."print w + e

2、Python 的规则里,只要一行以“冒号(colon)”: 结尾,它接下来的内容就应该有缩进。

3、可以直接将 elements 赋值为 range(0,6),而无需使用 for 循环

4、从命令行参数读入的数据都是字符串形式,如果需要按整数形式处理,则需要类型转换函数:int(counts)

5、使用函数时候,要注意函数内和函数外变量的作用范围(生命周期)

6、range函数的增加序列差值只能为1,要想改变循环增加的差值,可以用while-loop结构

7、判断字符从next是否为纯数字:

参考:Python判断字符串是否为纯数字

8、yield关键字用法

参考:Python yield浅析



原创粉丝点击