接触python的第2天:了解变量和打印

Posted 余小张

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接触python的第2天:了解变量和打印相关的知识,希望对你有一定的参考价值。

1变量不用定义类型, 可以直接赋值

>>> a =5
>>> a
5

>>> a=hello
>>> a
hello

 

2 变量类型可以直接用type显示

>>> type(a)
<class str>

>>> a=4
>>> type(a)
<class int>

 

3 print 可以打印数值,里面要有‘’ 或 “”

>>> print(a)
4
>>> print(hello)
hello
>>> print("hello")
hello

错误示范:

>>> print(hello)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
print(hello)
NameError: name ‘hello‘ is not defined

 

以上是关于接触python的第2天:了解变量和打印的主要内容,如果未能解决你的问题,请参考以下文章