讨论区讨论详情

【暑期班】计算机科学和Python编程导论
2016-09-01 15:19:20

Lecture1:Goals of the course; what is computation; introduction to data types, operators, and variables

Python

  • High (√) VS. low
  • General (√) VS. targetted
  • Interpreted (√) VS. compile

    1. Syntax语法:what are legal expressions
      “cat dog boy “
    2. Static semantics 静态语义:which programs are meaningful
      “   My desk is Suson“
    3. Full semantics 完整语义:what does program mean
      what will happen when i run it

Operation
+ - * /

>>>'a'*3'aaa'>>>3/50>>>3**327
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Variables

>>> a = 3>>> print a3
  • 1
  • 2
  • 3



Lecture2:Operators and operands; statements; branching, conditionals, and iteration

Operators and operands

>>> 'ab' + 'c''abc'>>> 3 + 'c'Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'>>> str(3) + 'c''3c'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • type conversion 类型转换  str(3)
  • type checking 类型检查  weak VS. strong typing
    TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’
  • type discipline
  • operation precedence 算符优先
    * >> / >> + -    when is doubt, use ()
>>> 'a' < 3False>>> 4 + '3'True>>> 951>>> 954>>> 34523
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • Variables has a value--Assignment x = 3
  • type of Variables--get from value
    Dynamic types 动态类型
    x = ‘abc’

    don’t change types arbitrarily 不要反复无常的改变变量类型

  • Variables used any place it’s legal to use value


statements

  • statements = legal commands that Python can interpret
  • print, assignment

branching 分支

  • change the order of instructions based on some test (usually a value of a variable)
  • Syntax
    冒号colon :  begin a sequence of instructions
    identifies a block of instructions.
冒号: start
carriage 回车 is end
  • 1
  • 2
x = 15if(x/2)* 2 == x:    print 'Even'else: print 'Odd'
  • 1
  • 2
  • 3
  • 4

conditionals 条件

if语句可嵌套if <some test> :
    Block of instructions.else: 
    Block of instructions.
  • 1
  • 2
  • 3
  • 4
  • 5
  • Boolean combination:AND, OR, or NOT

iteration 迭代 or loops 循环

# y = x的平方y = 0x = 3itersLeft = xwhile(itersLeft>0) :
    y = y + x
    itersLeft = itersLeft -1print y


回复:

还没有人发言哦,来抢沙发吧~

请先登录

说点什么吧~

学堂公告

各位MOOCer大家好 (^-^)V

欢迎来到学堂在线广场~

在这里你可以玩活动,看资讯,晒笔记。

还可以交学友、发心情、聊人生。

在学堂的每一天,就从这里开始吧!

点击 广场指南 了解更多

推荐活动

我要举报
提交