1,python的自述:
在这里插入图片描述
print(520)
print('hello')
print(3+1)
# 将数据输出到文件中 a+:文件不存在就创建,存在就追加
fp=open('D:/yang.txt','a+')
print('hello',file=fp)
fp.close()
# 不进行换行输出
print('hello','world')
# 转义字符,\n换行
print('hello\nworld')
# 占完水平制表符
print('hello\tworld')
# 输出world覆盖了hello,回车
print('hello\rworld')
# 退一格
print('hello\bworld')
print('http:\\\\www.baidu.com')
print('老师说:\'你们好\'')
# \'单引号 \“双引号
# 若不希望转义字符起作用,那么使用原字符,在字符串前面加上r或者R,但是最后'一个'字符不能是反斜杠\
print(r'hello\bworld')
>>> s1=' '
>>> s2=' '
>>> s1 is s2
True
>>> s1='%'
>>> s2='%'
>>> s1 is s2
True
>>> s1='WWWW'
>>> s2='WWWW'
>>> s1 is s2
True
#不符合标识符,内容是相同,但是内存地址不一样
>>> s1='WESAD%'
>>> s2='WESAD&'
>>> s1==s2
False
>>> s1='WESAD&'
>>> s3='WESAD&'
>>> s1==s3
True
>>> s1 is s3
False
>>> id(s1)
1997937708720
>>> id(s3)
1997937917872
>>> a='abc'
>>> b='ab'+'c'
>>> c=''.join(['ab'+'c'])
>#b是在编译之前存储的
>>> a is b
True
>>> a is c
True
#c是在运行的时候新开的内存地址
>>> c=''.join(['ab','c'])
>>> a is c
False
>>> a=-4
>>> b=-4
>>> a is b
True
>>> a=-6
>>> b=-6
>>> a is b
False
>>> import sys
>>> a='abc%'
>>> B='abc%'
>>> a is B
False
>>> a=sys.intern(B)
>>> a is B
True
pychar对字符串进行了优化处理。原来不驻留的,在这驻留