1. 由123 and 456结果引发的思考:
These are the Boolean operations, ordered by ascending priority:
Operation | Result | Notes |
---|---|---|
x or y | if x is false, then y, else x | (1) |
x and y | if x is false, then x, else y | (2) |
not x | if x is false, then True, else False | (3) |
Notes:
s = "hello \n world"
print s
input = raw_input()
print input
输入“hello \n world”
grade = 97
if grade < 60:
print 'E'
elif grade >= 60:
print 'D'
elif grade >= 70:
print 'C'
elif grade >= 80:
print 'B'
elif grade >= 90:
print 'A'
作者的本意是筛选正确的分数顺序,无奈使用if-elif 语句时顺序排列确有问题,正确的顺序应该是本程序从下至上依次淘汰。
sum = 0
i = 1
while sum < 100:
if i % 2 != 0:
sum += i
i += 2
print sum
l = [1,2,3,4]
l1 = l
l = [2,2,3,4]
print 'l = ',l
print 'l1 = ',l1
n = 1
n1 = n
n = 0
print 'n = ',n
print 'n1 = ',n1
l = [1,2,3,4]
l1 = l
l[0] = 2
print 'l = ',l
print 'l1 = ',l1
明确两点:
lst = [1, 2, 3]
def f(lst):
lst = [4, 5, 6]
f(lst)
print lst
def f2(lst):
lst[0] = 0
f2(lst)
print lst
同样的是使用了 “ = ” 这个操作,得到的效果是不一样的,仍然跟上面说的有关系:
a = 0
def f(a):
a = 2
f(a)
print a
而第二段代码并没有赋予新的值,也就是说地址指针一直都是指向原lst 的地址,是对原来的 lst 上做改变,所以不需要返回值就可以改变原 lst 值
list = [1, 2, 3]
print list.append(4)
print list
两次 print 的结果是不一样的。
def area_triangle(base, height):
return 0.5 * base * height
b = '5'
h = '2+2'
print 'Area of triangle with base', b, 'and height', h, 'is', area_triangle(b, h)
在这里会有一个报错:TypeError: can't multiply sequence by non-int of type 'float'
print '3+2'
结果会是什么呢?很容易惯性的将结果计算出来,认为是5,但是这却是一个String,并不会进行计算,直接打印出引号里面的text
#!/usr/bin/python
# -*- coding: utf-8 -*-
# using pip
pip install virtualenvwrapper-win
# using easy_install
easy_install virtualenvwrapper-win
# from source
git clone git://github.com/davidmarble/virtualenvwrapper-win.git
cd virtualenvwrapper-win
python setup.py install
使用pip 常常会失败,因为网络连接可能根本找不到这样的distribution:not matching xxx????????????