Learn python the hard way 2nd 学习过程中的问题记录

这本书比较简单,按照每天10章的目标完成。

-----------------------第一次,7月12日,0 - 10章----------------------

根据作者的提示要使用python2而不是3,因为py3的版本有许多问题。

Exercise 1:

1. 在""和‘’在py里面都是字符串,使用两种标准的目的是为了简便,见下面的例子:

  print "I'd much rather you 'not'."

  print 'I "said" do not touch this.

2. 在extra credit中,在同一行输出采取下面的措施


Exercise 5:

1. 多参数的标准化输出采用 %(parm1, parm2)的这种形式

  print "he's got %s eyes and %s hair" %(my_eyes, my_hair)

2. 格式化输出还是c语言的那一套,其中要重点注意的是%r,这个问题丢到后面来专门写一篇日志研究。

Exercise 6:

重点注意%r和%s的区别

Exercise 7:

1. 字符串乘以数字就是字符串重复的倍数

2. 逗号是两行连续

Exercise 9:

1. 使用\n换行

2. """ 和"""中间的内容保持原来的格式

3. 熟悉%r的用法

-----------------------------------7月23日--------------------------------------------

Exercise 11:

raw_input()函数可以读取基本数据类型。

Exercise 12:

1. 提示的另外一种方式,age = raw_input( '提示内容')

2. pydoc + 函数名的方式即可查询函数的具体用法

Exercise 13:

1. from  s sys  t import argv

   script, first, second, third = argv

2. 发现

    str = 'sicily test'

    print 'this is a test', str

    print 'this is a test %s' %str

这两句话的输出并没有什么明显的不同,有点忘记了。

Exercise 14:

Exercise 15:

 txt = open(filename)

 print txt.read()

Exercise 16:

文件操作:close, read, readline, truncate, write

1. 在我下载的这个版本看不到第12行应该是 target = open(filename, 'w')

Exercise 17:
1. from os.path imports exists
2. len(data) #测量data长度bytes
3. exists(filename) #判断filename是否存在
Exercise 18:
1. 函数的定义
方式一:def print_two(*args):
                      arg1, arg2 = args
                      print 'arg1: %r, arg2: %r' %(arg1, arg2)
方式二:def print_two_again(arg1, arg2):
                      print 'arg1: %r, arg2: %r' %(arg1, arg2)

--------------------------------------------------------7月25日------------------------------------------------------

Exercise 19:
>>> print f.seek.__doc__
seek(offset[, whence]) -> None.  Move to new file position.

Argument offset is a byte count.  Optional argument whence defaults to
0 (offset from start of file, offset should be >= 0); other values are 1
(move relative to current position, positive or negative), and 2 (move
relative to end of file, usually negative, although many platforms allow
seeking beyond the end of a file).  If the file is opened in text mode,
only offsets returned by tell() are legal.  Use of other offsets causes
undefined behavior.Note that not all file objects are seekable.

Exercise 24:
def secret_formula(started):
    jelly_beans = started * 500
    jars = jelly_beans / 1000
    crates = jars / 100
    n return jelly_beans, jars, crates
    start_point = 10000
    beans, jars, crates = secret_formula(start_point)

python不像其他基础语言一次只能返回一个参数,在图中的例子,python的一个函数可以返回多个值。

Exercise 25:
 我再windows下面调用python的dos界面有点问题,在此节我发现了新的调用方式,解决了我学习中的问题

Exercise 28:

学会了做逻辑运算的步骤:

Whenever you see these boolean logic statements, you can solve them easily by this simple process:
1. Find equality test (== or !=) and replace it with its truth.
2. Find each and/or inside a parenthesis and solve those first.
3. Find each not and invert it.
4. Find any remaining and/or and solve it.
5. When you are done you should have True or False.

Exercise 30:
1. Why does the code under the if need to be indented 4 spaces? A colon at the end of a line is how you tell Python you are going to create a new
"block" of code, and then indenting 4 spaces tells Python whatlines of code are in that block. This is exactly the same thing you did when you made
functions in the first half of the book.
2. if-else的用法:
if cars > people:
    print 'We should take the cars.'
elif cars < people:
    print 'We should not take the cars.'
else:
    print 'We can not decided.'

Exercise 32:
 Python中的list功能确实要比类C语言强大很多。

Exercise 37:
Keywords
• and
• del
• from
• not
• while
• as
• elif
• global
• or
• with
• assert
• if
• pass
• yield
• break
• except
• import
• print
• class
• exec
• in
• raise
• continue
• finally
• is
• return
• def
• for
• lambda
• try
Data  Types
For data types, write out what makes up each one. For example, with strings write
out how you create a string. For numbers write out a few numbers.
• True
• False
• None
• strings
• numbers
• floats
• lists
String s Escapes Sequences
For string escape sequences, use them in strings to make sure they do what you
think they do.
• \'
• \"
• \a
• \b
• \f
• \n
• \r
• \t
• \v
String Formats
Same thing for string formats: use them in some strings to know what they do.
• %d
• %i
• %o
• %u
• %x
• %X
• %e
• %E
• %f
• %F
• %g
• %G
• %c
• %r
• %s
• %%
Operators
Some of these may be unfamiliar to you, but look them up anyway. Find out what
they do, and if you still can't figure it out, save it for later.
• +
• -
• *
• /
• //
• %
• <
• >
• <=
• >=
• ==
• !=
• <>
• ( )
• [ ]
• { }
• @
• ,
• :
• .
• =
• ;
• +=
• -=
• *=
• /=
• //=
• %=
• **=

Exercise 39:
' '.join(things) reads as, "Join things with ' ' between them." Meanwhile, join(' ',things) means, "Call join with ' ' and things."

Exercise 40:
1. list中用的是中括号,而dictionary里面用的是大括号。

2. 函数名也是变量,可以用其他变量替代。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值