小学生学python(三)

这一节主要讲序列,包含三种:字符串,列表,元组。

1  字符串

 就是一系列字符。比如:

'this is string' 

"this is string"

'这是字符串'

"这是字符串"

给一个变量赋值并打印出来

name = 'this is string' 
print(name)

this is string这个字符串是保存在内存的栈中的,有个地址,一般用十六进制的0x开头表示,比如0x000003545,内存的地址跟我们生活中的门牌号相似。但是name是怎么取到这个字符串值得呢,name自身也是在栈中有个地址,里面保存了一个指向字符串this is string所在地址的指针。当我们调用print函数的时候就能显示this is string

对字符串进行拼接

first_name = "jack"
last_name = "ma"
full_name = first_name + " " + last_name
print(full_name)

直接使用操作符+来拼接字符串,输出结果就是:jack ma

猜你喜欢

转载自www.cnblogs.com/ikel/p/9119416.html