object 对象 attribute 属性 method方法=function函数
数据类型data types 数字number 字符string 列表list 字典dictionary 元组()集合set
数字包括 integer整数 浮点数floating
基本运算 + - * / //整除取商 **幂乘方 %求余
variable变量name=value值 变量赋值之后才能使用否则报错 命名规则只能包含字母数字下划线,不能以数字开头,不能使用关键字!
Python关键字 false class finally is return none continue for lambda try true def from nonlocal try and del global not with as elif if or yield assert else import pass break except in raise
字符串是各种字符比如字母数字标点符号,单双引号包裹都行!
转义字符 需要在字符中使用特殊字符时,用反斜杠\转义字符
格式化字符串f-strings name='guozhan' print(f'my name if ')
字符串method upper变大写 name='hello' print(name.upper())
索引index 定位一个物体的位置!a='hello' a[0] a[-1] o a[1:4] ell 包头不包尾
列表list 由特定顺序元素组成 方括号包裹,逗号分隔元素,可装多种元素!a=[1,2,a,5] a[:3] a[1:]到尾 a.append(100)追加元素 a.insert(2,300)下标2处插入元素300 a.pop()删除最后一个元素 a.pop(2)删除下标2处元素 len(a)查询列表长度多少个元素
函数function 是带名字的代码块 可完成特定任务便于重复使用!
def smile(): def hello(name,age): #形参
return 'xiaolian' print('hello '+name+' you are '+str(age))
smile() #执行函数 hello('guozhan',18) #实参
def mianji():
name=input('shurunidemingzi')
width=int(input(name+' shurudibian'))
height=int(input('shurugaodu'))
result=width*height/2
print(f'mianjishi:')
mianji()
字典dictionary height={“张三”:180,“张四”:190,} height[“张五”]=170增加键值对 height[“张三”]=188修改值 del height[“张三”]删除键值对
if语句根据结果决定是否执行! 0的布尔值是false 其它数字都是ture 空的字符串bool('')也是false 空的元组bool([])数组都是false
>=
a=1
b=-1
if a==b:
领取专属 10元无门槛券
私享最新 技术干货