1、tab缩进容易出错,尤其在流程控制、循环、函数体里面,python严格要求空格必须一致
2、自带有很多函数库,在操作相关的函数时,需要使用import引入函数库;如:import math
3、数据类型很多;包括int、float、str、bool(True、False)、None、list、tuple、set
4、全大写的一般都是常量
5、运算符:+、-、*、/、%、&(交集)、|(并集)
6、list(有序集合)可以随时修改;例如: names = [‘tom‘, ‘linda‘, ‘sam‘];
len(list)查看list的长度,
list.append() 在list后面添加元素,
list.insert(‘位置‘, ‘值‘) 指定索引位置插入元素
list.pop() 删除末尾元素
list.pop(‘索引‘) 删除指定位置元素
list[‘key‘] 读取元素的值
7、tuple(元组)一旦初始化就不能修改;例如:t = (‘A‘, ‘B‘, [‘tom‘, ‘linda‘, ‘sam‘])
tuple里面可以是list集合,但是list对应的指向不能改变,list里面的值可以修改
8、条件判断;条件判断后面的冒号(:)一定不能少
height = 1.75
weight = 80.5
str = weight / (pow(height, 2))
if str < 18.5:
print(‘过轻‘)
elif str>=18.5 and str<25:
print(‘正常‘)
elif str>=25 and str<28:
print(‘过重‘)
elif str>=28 and str<32:
print(‘肥胖‘)
elif str>32:
print(‘严重肥胖‘)
else:
print(‘这个世界容不下你了‘)
9、name = input() ;可以让输入值,name就是输入的值
10、循环;条件判断后面的冒号(:)一定不能少
1>:for value in list:
sum = 0
number = [1,2,3,4,5,6,7,8,9,10]
for i in number:
sum = sum+i
print(sum)
2>:while 条件 :
sum = 0
n = 10
while n>0:
if n < 5:
break #终止循环
continue #终止本次循环
sum = sum + n
n = n - 1
print(sum)
原文:https://www.cnblogs.com/liujiyun/p/9140848.html