python缩进格式错误修改_Python,意外的缩进错误解析,Pythonunexpectedindent,解决,方法...

python编程基础

遇到问题上谷歌

StackOverlow

提出你想做什么,而不是你做了什么

指出错误的地方,简要描述

将错误和代码复制

表达式

1.表达式

表达式包含 值(2)和 操作符(+)

Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>> 2=2

SyntaxError: cannot assign to literal

>>> 2+2

4

>>> 2

2

>>>

PS:常见python错误 http://nostar.com/automatestuff/

1.2数学操作符(优先级由高到低)

** 指数

% 取模/取余数 22%8=2…6 取6

// 整除/商数取整 22//8=2 取2

/ 除法 22/8=2.75

*乘法 - 减法 + 加法

>>> 2=2

SyntaxError: cannot assign to literal

>>> 2+2

4

>>> 2

2

>>> 2**3

8

>>> 28

28

>>> 22%8

6

>>> 22/8

2.75

>>> 22//8

2

>>> 22+8

30

>>> 22-8

14

>>>

常见数据类型:整形,浮点型,字符串

数据为整数类型的叫整形

数据带小数部分的叫浮点型

用’'包含的叫字符串

SyntaxError: invalid character in identifier

>>> 12+12

24

>>> 12.3+14.2

26.5

>>> 'a'+'b'

'ab'

>>>

PS:在中文输入法的模式下,无法正确输入(.)。

变量与复制语句

变量相当于一个黑盒:用来保存值

>>> s=10

>>> s

10

>>> a=2

>>> a

2

>>> s+a

12

>>> s=a+2

>>> s

4

>>> s=s+2

>>> s

6

>>>

PS:第一次存入值 相当于初始化,此后可在表达式中使用它 ,赋新值时会被覆盖。

变量名

1.3变量名的命名规则

1.只能是一个词

2.只能包含字母、数字和下划线

3.不能以数字开头

合法的变量名:

balance、curBalance、cur_dad、_dad、SPASDA、ac4

不合法的变量名:

ce-sad、asd asd、2sad、32、das$sad、‘dsa’

第一个程序

注意文件和交互式环境的区别

交互式环境窗口总是有>>>提示符

文本编辑器窗口没有>>>提示符

# This program says hello and asks for my name

print('hello world!')

print('What is you name?') # ask for their name

myName=input()

print('It is good to meet you,'+myName)

print('The length of your name is:')

print(len(myName))

print('What is your age?') #ask for their age

myAge=input()

print('You will be'+str(int(myAge)+1)+'in a year.')

第一个错误

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mYkwAmIc-1595471890952)(file:///C:\Users\土豆666\Documents\Tencent Files\1036372306\Image\C2C@CU]%7OQ1XB%~DO1GAL(9L3.png)]

警告:unexpected indent

错误一unexpected indent 解决方法

https://blog.csdn.net/weixin_42717711/article/details/82800192

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTQzMTUwNQ==,size_16,color_FFFFFF,t_70

源文件中的

myAge=input()

没有首行缩进,多打了一个空格

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值