python基本数据类型和用法

本文详细介绍了Python中的基本数据类型,包括整型(int)在Python 2与Python 3中的区别,以及字符串(strings)的使用方法。针对整型,文章解释了在不同版本Python中整型的存储范围和限制;对于字符串,则涵盖了单引号、双引号字符串的使用及转义字符的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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组成的序列。

单引号字符串

双引号字符串

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

转义字符--换行

8d0dbcdc7d7ebeb7f32dc3b76f9848e1b19.jpg

按照输入格式打印字符串

 

转载于:https://my.oschina.net/codepencil/blog/1926918

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值