python第一章自测_python第一章

1、计算机语言

机器语言、汇编语言、高级语言(编译和解释两种)

编译:执行效率高,跨平台差

解释:执行速度低,跨平台好

机器语言

优点是最底层,速度最快,缺点是最复杂,开发效率最低

汇编语言

优点是比较底层,速度最快,缺点是复杂,开发效率最低

高级语言

编译型语言执行速度快,不依赖语言环境运行,跨平台差

解释型跨平台好,一份代码,到处使用,缺点是执行速度慢,依赖解释器运行

2、python解释器类型

常用的CPython,pypy

3、python解释器安装,第一个python程序

两种执行方式:

1)文件执行

写入文件后执行,能够保存代码  ,python3 文件名

2)交互器执行

交互器的作用:能够实时调试代码

4、变量

1)概念:变化的数

2)作用:在内存中标记和储存信息,以便其他程序调用

变量的作用 (3分钟)

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

3)命名规范:

变量名只能是 字母、数字或下划线的任意组合

变量名的第一个字符不能是数字

以下关键字不能声明为变量名['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

4)命名习惯:

驼峰体:

AgeOfOldboy = 56

下划线:

5)命名变量的low方式:a)中文 b) 过长  c)词不达意

5、常量

大写字母表示

6、输入 input  输出 print

7、注释

单行用#,多行用''' '''或用三对双引号""" """

代码注释原则:

不用全部加注释,只需要在自己觉得重要或不好理解的部分加注释即可

注释可以用中文或英文,但绝对不要拼音噢

8、数据类型

1)数字:int  long .float,python3后没有long了

2)字符串 加了引号的就是字符串

单引号 双引号  多引号(多行字符)

字符串拼接,相加和相乘

>>> name

'Alex Li'

>>> age

'22'

>>>

>>> name + age #相加其实就是简单拼接

'Alex Li22'

>>>

>>> name * 10 #相乘其实就是复制自己多少次,再拼接在一起

'Alex LiAlex LiAlex LiAlex LiAlex LiAlex LiAlex LiAlex LiAlex LiAlex Li'

注意,字符串的拼接只能是双方都是字符串,不能跟数字或其它类型拼接

3)布尔

9、格式化输出

(1)用到占位符 %+格式类型

name = input("name:")

age = int(input("age:"))

hometown = input("hometown:")

job = input("job:")

print(type(age))

info = '''

------------info of %s-------

name : %s

age: %d

hometown: %s

job: %s

------------end--------------

'''% (name,name,age,hometown,job)

print(info)

(2)format函数

info = '''

------------info of {}-------

name : {}

age: {}

hometown: {}

job: {}

------------end--------------

'''.format(name,name,age,hometown,job)

print(info)

10、运算符

1)算数

+-* / ** % //

2)比较

== > < <> != >= <=

3) 赋值

= += -= *= /= %= **= //=

4)逻辑

and or not

11、流程控制

1)单分支

2)双分支

3)多分支

12、while循环

while 条件:

执行代码

13、break and continue

break:完全跳出循环

continue:跳出本次循环,继续下次循环

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值