1 # -*- coding:utf-8 -*-
2 print "hello world"
3 print("hello world")
这里面使用了2中print方式,下面会逐行解释代码并说明2中print方式区别在哪里
# -*- coding:utf-8 -*- #这行代码的意思是使用utf-8编码格式,主要用于中文
1 print "hello world"  #print""代码格式在python 2.7版本中使用
1 print("hello world")#print("")代码格式在python 3版本中使用
1 print #输出'int'整数、'str'字符串、'list'列表、'dict'字典等类型的内容

2.7和3版本的区别在于print后面2.7版本不需要加()而3版本改为必须在()中输入要输出的内容

 

变量:

1 a = 1
2 b = "dlrb"
3 print(a)
4 print(b)

变量的阅读顺序是 将整数1赋值给变量a;将字符串dlrb赋值给变量b,之后可以使用print直接输出变量名就可以输出我们想要的内容了

输出结果:

1
dlrb

变量名的命名需要遵循以下规则:

1.变量名只能包括字母、数字、下划线并且不能以数字开头
2.python自带关键字不能做变量名使用
3.Python的变量名是区分大小写,dlrb与Dlrb是2个变量

相关文章:

  • 2021-06-19
  • 2022-01-05
  • 2021-04-24
  • 2022-01-12
  • 2022-12-23
  • 2022-01-01
  • 2021-04-27
  • 2021-12-25
猜你喜欢
  • 2021-07-19
  • 2021-12-22
  • 2021-09-08
  • 2021-06-30
  • 2022-01-19
  • 2021-06-15
  • 2022-01-17
相关资源
相似解决方案