python学习笔记(一) ——变量

Python系列文章目录

第一章 python学习笔记(一) ——变量
第二章 python学习笔记(二) ——控制流工具
第三章 python学习笔记(三) ——数据结构
第四章 python学习笔记(四) ——模块


计算

1. 数字类型

  • int
    32位整数,具有无限精度。
  • float
    -32位浮点数,用C的double实现
    -complex
    复数包含实部和虚部,分别以一个浮点数表示。
  • Decimal
    decimal 模块旨在支持“无偏差,精确无舍入的十进制算术(有时称为定点数算术)和有舍入的浮点数算术”。
  • Fraction
    分数实例可以由一对整数,一个分数,或者一个字符串构建而成。

2. 数字运算±*/(可使用小括号)

note:除法

>>> 8 / 5  # division always returns a floating point number
1.6
>>>17 / 3  # classic division returns a float
5.666666666666667
>>>17 // 3  # floor division discards the fractional part
5
>>>17 % 3  # the % operator returns the remainder of the division
2
>>>5 * 3 + 2  # floored quotient * divisor + remainder
17

3.字符串

(1) 如果不希望前置 \ 的字符转义成特殊字符,可以使用 原始字符串,在引号前添加 r 即可:

>>> print('C:\some\name')  # here \n means newline!
C:\some
ame
>>> print(r'C:\some\name')  # note the r before the quote
C:\some\name

(2) 索引的时候,左包括,右不包括。

>>> word[0:2] # characters from position 0 (included) to 2 (excluded)
'Py'

(3) 序号索引不能溢出边界,切片索引可以溢出边界

>>> word[4:42]
'on'
>>> word[42:]''

(4) python字符串不能改,只能重新新建一个

>>> word[0]='J'
Traceback (most recent call last):
File"<stdin>", line1, in<module>TypeError:'str' object does not support item assignment

>>>'J'+word[1:]
'Jython'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值