python 可变类型和不可变类型
Posted 浮云飘渺的狮子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 可变类型和不可变类型相关的知识,希望对你有一定的参考价值。
不可变类型:
数字 int
字符串 str
浮点数 float
布尔类型 bool
元组 tuple
特点: 这些数据都是不可以直接修改的,如果在修改或赋值时,都会开辟一个新空间
可变类型:
特点: 这个些数据类型,是可以直接在原对象上进行修改数据,修改完成后,并不影响原对象地址
!--5f39ae17-8c62-4a45-bc43-b32064c9388a:W3siYmxvY2tJZCI6IjE3ODUtMTU1NTY3MjcwMTQ1NiIsImJsb2NrVHlwZSI6InBhcmFncmFwaCIsInN0eWxlcyI6eyJhbGlnbiI6ImxlZnQiLCJpbmRlbnQiOjAsInRleHQtaW5kZW50IjowLCJsaW5lLWhlaWdodCI6MS43NSwiYmFjay1jb2xvciI6IiIsInBhZGRpbmciOiIifSwidHlwZSI6InBhcmFncmFwaCIsInJpY2hUZXh0Ijp7ImRhdGEiOlt7ImNoYXIiOiLkuI0ifSx7ImNoYXIiOiLlj68ifSx7ImNoYXIiOiLlj5gifSx7ImNoYXIiOiLnsbsifSx7ImNoYXIiOiLlnosifSx7ImNoYXIiOiI6In1dLCJpc1JpY2hUZXh0Ijp0cnVlLCJrZWVwTGluZUJyZWFrIjp0cnVlfX0seyJibG9ja0lkIjoiMjg2OS0xNTU1NjcyNzAxNDU2IiwiYmxvY2tUeXBlIjoicGFyYWdyYXBoIiwic3R5bGVzIjp7ImFsaWduIjoibGVmdCIsImluZGVudCI6MCwidGV4dC1pbmRlbnQiOjAsImxpbmUtaGVpZ2h0IjoxLjc1LCJiYWNrLWNvbG9yIjoiIiwicGFkZGluZyI6IiJ9LCJ0eXBlIjoicGFyYWdyYXBoIiwicmljaFRleHQiOnsiZGF0YSI6W3siY2hhciI6Ilx0In0seyJjaGFyIjoiXHQifSx7ImNoYXIiOiLmlbAifSx7ImNoYXIiOiLlrZcifSx7ImNoYXIiOiIgIn0seyJjaGFyIjoiaSJ9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Y2hUZXh0Ijp7ImRhdGEiOltdLCJpc1JpY2hUZXh0Ijp0cnVlLCJrZWVwTGluZUJyZWFrIjp0cnVlfX1d-->以上是关于python 可变类型和不可变类型的主要内容,如果未能解决你的问题,请参考以下文章
python可变类型和不可变类型
python可变类型和不可变类型
Python的可变和不可变类型
python 可变类型和不可变类型
python 可变类型和不可变类型
python全栈开发第五篇Python可变数据类型和不可变数据类型