[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
如果没有特别说明的话,本章后面我们输入的所有内容都是在
Python
解释器中输入
的。如果你用的是
IPython
,提示符是类似
In [1]:
这样的。
2.1
基本数据类型
本节将学习
Python
中的简单数据类型。这些数据类型都在
Python
的信息处理过程中发挥
重要作用。我们要学习的数据类型包括字符串型、整型、浮点型和其他非整数类型。
2.1.1
字符串
我们要学习的第一个数据类型是字符串型。你之前可能没有在这种语境下听过“字符串”
这个词,但字符串实际上就是用引号标记的文本。字符串里可以包含数字、字母和符号。
下面都是字符串的例子:
'cat'
'This is a string.'
'5'
'walking'
'$GOObarBaz340 '
将上面任一字符串输入到
Python
解释器里,解释器会返回相同的内容。程序仿佛在说:
“嘿,我听到你了。你说的是
'cat'
(或任何你输入的内容)。”
只要字符串位于成对的引号(单引号或双引号都可以)之间,其内容无关紧要 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.