python基本数据类型和简单用法

一、int 整形范围

How Big Is an int?

In Python2, the size of an int was limited to 32 bits, which is enough to store an integer from -2,147,483,648 to 2,147,483,647. A long can store 64 bits. Integers larger than the range will cause Integer Overflow.

In case you wonder where does this range come from. Computers store numbers in its binary format, 32 bits means we have 32 binary bits to store a number. That's why we can only store 232232 different integers. Since we want to store both positive numbers and negative numbers at the same time, each side will get 231231 numbers, which is 2,147,483,648.

In Python3, an int can handle any integer no matter how large it is without causing overflow.

Python3中整形可以用任意大小,不会出现溢出情况。

jupyter notebook中测试如下:

 

二、Strings 字符串

The strings is a sequence of characters. strings是character组成的序列。

单引号字符串

 

双引号字符串

 

转义字符--输出双引号&单引号

 

转义字符--换行

 

按照输入格式打印字符串

 

 

posted @ 2019-05-24 14:25  西风的博客  阅读(264)  评论(0编辑  收藏  举报