python复习

python复习

第一章
1.除法://是取商的整数部分,%是取余数,两种计算的结果都是int
2.乘方:** 例:a**b指a的b次方
3.#是注释的意思
4.What you input is always a string:
The function input() reads your input as a string. Even if you typed 23.
input()的内容默认为字符,除非用int(input())转换
5. print(‘A’+‘B’)会显示“AB” ,不会自动空一格。需空格则需要自己加,如print(‘A ’+‘B’)
但是print(‘A’,‘B’)则会输出A B
7. a=input()
b=input()
则a会读取第一个输入的数,b会读取第二个输入的数
8. python中字符串可以用‘ ’或“ ”录入
9. Every real number can be represented as an object of type “float”.
10. Python can’t multiply strings.
例:
在这里插入图片描述

第二章:
1.The division / always gives you a float (a floating-point real number, an object of type float).
11. The exponentiation ** also returns a float when the power is negative.
12. 科学记数法:1.496×10的11次方在python中表示为1.496e11
13. float objects to int objects:
第一种方法:
直接用int()转化,但是这样会舍弃小数部分
第二种方法:
用round()转化,则会四舍五入
在这里插入图片描述
5. 调用the math module时用import math,而且使用函数前要在函数名前加"math.",如 math.ceil()
6. 绝对值函数为abs(),不需要调用the math module
7. math模块的一些函数:https://blog.csdn.net/lijiahong2012/article/details/52416400

第三章
1.The comparison operators in Python may be chained like this: a == b == c or x <= y >= 10. It’s a rare thing among programming languages.
2.bool()只会显示true或false。bool表示布尔型变量,也就是逻辑型变量的定义符。
例:在这里插入图片描述
3.If you have more than two options using the conditional operator, you can use if… elif… else statement.

第四章
1.Step can be negative
To iterate over a decreasing sequence, we can use the extended form of range() with three arguments — range(start_value, end_value, step). When omitted, the step is implicitly equal to 1. However, it can be any non-zero value. The loop always includes start_value and excludes end_value during iteration:
2.sep=’ xx '指输出字符时字符与字符之间用xx相隔;end=‘xx ’指当y一个print()里的所有数据输出后,不换行,只是用xx与下一个print()输出的隔开。默认下为换行。

第五章
1len(some_string) returns how many characters there are in a string:
2.Every object in Python can be converted to string using the function str(some_object). So we can convert numbers to strings:
3.当index为负数时,-1是一个数组最末尾的元素所对应的index
例:在这里插入图片描述
4.index为正或为负时的summarize:
在这里插入图片描述
5.In fact in Python there are no variables. They are only names that are pointing to objects.(指针)这点和c有很大的不同
6.S[a?️d] In this case only the characters with the indexes a a + d, a + 2 * d and so on are taken, until character with index b is reached and, as usual, not including it.
这也是和c、matlab不同的地方,python中公差是放在末尾。
7.object_name.find(arguments)用于按照顺序查找所指定字符在字符串中对应的index,如果这个字符不在字符串中,则returns -1。
object_name.rfind(arguments)则是倒序查找。
拓展:s.find(substring, left, right):
the search is performed inside the s[left:right] slice. If you specify only two arguments, like s.find(substring, left), the search is performed in the slice s[left:], that is, starting with the character at index left until the end of a string.但这种方法显示的index是在整个字符串中的对应的index,而不是这一小段中的index
8.s.replace(old, new) takes the string s and replaces all occurrences of substring old with the substring new.
s.replace(old, new, count)则可以指定替换次数
9.s.count(substring)计算指定字符在一个字符串中出现的次数,而s.count(substring, left, right)则可指定查找的区间,left和right可用index表示

第六章
1.while/for循环也可搭配else使用。一般用于while/for里有break的时候,如果在while/for中该break未被实行,则循环进行完毕后会执行else的部分,如果break,则不执行else部分
2.break/continue如果被放置在内置循环中,它只影响最内层的循环
3. Multiple assignment:
In Python it is possible for a single assignment statement to change the value of several variables
例:
在这里插入图片描述
这个特点可以解决斐波那契数列:
在这里插入图片描述

第七章:
1.len(数组名)可以计算一个数组所含元素数量
2.数组名.append():创建数组
例:
在这里插入图片描述

3.数组名.split():将一个字符串用指定的字符分割并组成数组。split()括号内可指定分割符(默认为空格),如split(’.’)
4.‘每个元素间隔之间的符号’.join(数组名)可在一行里显示数组的所有元素(去掉中括号)
例:
在这里插入图片描述

Ps:使用时应注意数组中的元素类型应是str,如果是其他类型则需先转换

5.数组中的元素是可以改变的
6.一些关于数组的操作:
在这里插入图片描述

第八章:
1.global 变量名可使变量变成全局变量,而不只是在一个小区域有效
例:
在这里插入图片描述
2.function()可以return多个变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值