ITPub博客

首页 > IT职业 > IT图书 > python分号表示什么

python分号表示什么

IT图书 作者:apnic 时间:2021-09-11 10:24:40 0 删除 编辑

python分号使用

每一条语句最后个加个分号;这是c,oc,java,php等语言中不可缺少的部分,但是对于python,分号是可加,可不加的

如:不加分号代码

>>> class Person:
    name = 'tom'
    age = 18

>>> p1 = Person()
>>> print(p1.age)
>>>

推荐学习《python教程》

加分号代码:

>>> class Student:
    name = 'tom';
    age = 18;

>>> stu1 = Student();
>>> print(stu1.age)
>>>

 注:建议最好还是不加分号,因为 python 是考换行来区分代码句的,当然有时候也可以加上;

python 使用分号的时候

>>> num1 = 1; num2 =2;>>> print(num1+num2);3
>>>

就是在一行 写多条代码句时,加上 分号;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1282/viewspace-2835022/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    121
  • 访问量
    792