***** WEEK-01 *****
- Lecture1 introduction to computation :
- Algorithm are recipes.
- An algorithm is a conceptual(概念的) idea, a program is a concrete instantiation(实例化) of an algorithm.
- 现代计算机的雏形:Stored program computer
- Basic Primitives: #操作系统用语范畴。是由若干条指令组成的,用于完成一定功能的一个过程
5. Programming Language:
Each programming language provides a set of primitiveoperations.
Each programming language provides mechanisms for combining primitives to form more complex, but legal, expressions.
Each programming language provides mechanisms for deducingmeanings or values associated with computations or expressions.
6.
7.
- Lecture2 Core Elements of Programs:
- python是一种解释型语言,会比编译型语言慢一点点。另一方面,一旦我们遇到错误或者漏洞时,通常能够更容易地找到引起错误的地方。
- scalar object 在python里有三种:int,float,bool。
- Remember that in Python words are case-sensitive(大小写敏感). The word True is a Python keyword (it is the value of the Boolean type) and is not the same as the word true.
- 优先级: 圆括号,not,and,or。
- round(2.6) -> 3.0; int(2.6) -> 2; 5*2 == 5.0 * 2.0 ->True
- non-scalar object: str -> /*注意和java中类似"abcd"[0:2] 这样的取下标从0到下标为1(2-1=1)*/
# 还有abcd[-1]也可以标号为0 -3 -2 -1,所以得到的是d
# ‘HELLO‘ == ‘hello‘ ->False
# str4[1:9:2] 字符串切片(slice)位置从1到9 - 1(即8),步长为2,即取索引值为1,3,5,7的子字符串(注索引值从0开始) str4 = ‘helloworld‘ str4[1:9:2] = ‘elwr‘
# str4[::-1] 就直接逆置字符串啦!!! 步长-1,就是指从后往前倒着来。且每一步是1,要是-2就是倒着来且间隔2
There‘s one other cool thing you can do with string slicing. You can add a third parameter,
k
, like this:s[i:j:k]
. This gives a slice of the strings
from indexi
to indexj-1
, with step sizek
. Check out the following examples:
>>> s = ‘Python is Fun!‘>>> s[1:12:2]‘yhni u‘>>> s[1:12:3]‘yoiF‘>>> s[::2]‘Pto sFn‘
The last example is similar to the examples[:]
. Withs[::2]
, we‘re asking for the full strings
(from index 0 through 13), with a step size of 2 - so we end up with every other character ins
. Pretty cool!
7. 关于函数 raw_input() 的使用。
8. 在 # 的后面写注释。
9. 缩进表示一个指令块,和java,C语言有点不一样哦
10. 比较不同类型的变量大小:
11. elif 相当于 else if; if句子说完之后的冒号不能漏写!
12. type函数:
1 if type(varB)==str or type(varA)==str: #此处利用了type函数,str int bool 都可以写 2 print(‘string involved‘)