现在的位置: 首页 > 综合 > 正文

Python学习笔记【1】

2013年07月28日 ⁄ 综合 ⁄ 共 696字 ⁄ 字号 评论关闭

1、%r和%s的区别

(1)stackflow 上面的一个解答

(2)

x = "There are %d types of people." %10
binary = "binary"
do_not = "don't"
y = "Those who know %s and those who %s." % (binary,do_not)

print x
print y

print "I said: %r." % x
print "I also said: '%s'." % y
print "I also said: %s." %y
print "I also said: '%r'." %y
print "I also said: %r." %y
hilarious = False
joke_evaluation = "Isn't that joke so funny?!%r"

print joke_evaluation % hilarious

w = "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浅析

【上篇】
【下篇】

抱歉!评论已关闭.