python shape()函数和format()函数用法

shape()

shape():读取矩阵长度,如shape[0]是读取矩阵第一维的长度。

1.参数是一个数时,返回为空:

 

 

2.参数是一维矩阵:

3.参数是二维矩阵:

 4.直接用shape()可快速读取矩阵的形状,shape[0]读取矩阵第一维的长度

 5.但某维度长度不一致时,读取所有维度时则不能读出长短不一致的维度

 format()

格式化字符串的函数,用来处理各种字符串

1.设置位置

python shape()函数和format()函数用法_第1张图片

2. 设置参数

print("名字:{name},性别:{sex}".format(name="哈哈",sex="girl"))

>>名字:哈哈,性别:girl

通过字典设置参数

site = {"name"="哈哈","sex"="girl"}

print("名字:{name},性别:{sex}.format(**site)")

>>姓名:哈哈,性别:girl

通过列表索引设置参数

list=['哈哈','girl']

print("名字:{0[0]},性别:{0[1]}".format(list))                  0是必须的

>>姓名:哈哈,性别:girl

3.向format()传入对象

python shape()函数和format()函数用法_第2张图片

>>value:为6

 

你可能感兴趣的:(python shape()函数和format()函数用法)