大家好!我是幻化意识流,简称意识流。现在我们继续Python的学习。
我们打开IDLE。
我们对图片中的信息解释一下:
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:01:55) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 3**2+5-6*7/8+3//9+27*4-(3+2.1)
111.65
>>> 'I'+'am'+'a'+'student.'
'Iamastudent.'
>>> 'I'+' '+'am'+' '+'a'+' '+'student.'
SyntaxError: unexpected indent 语法错误:意外缩进
错误信息发生的原因是在>>> 'I'中间有个空格
>>> 'I'+' '+'am'+' '+'a'+' '+'student.'
'I am a student.' 这样是不是看起来就很舒服了?
>>>
接下来,我们尝试用字符串和数值相加会发生什么:
>>> 'A'+1
Traceback (most recent call last):
File "
'A'+1
TypeError: can only concatenate str (not "int") to str
追溯(最近的调用最后一次):
文件“
‘A’+1。
TypeError:只能将字符串(不是“int”)连接到字符串
如果我们把1转换成字符串就可以连接了,如下:
>>> 'A'+str(1)
'A1'
留下节课思考题:‘A’*3 会输出什么结果?
see you .
页面更新:2024-03-17
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号