python 取余_【白话Python】Python的基本数据类型

5c1dd5648a575f0245b4a5ffcaa30b48.png
Python的整数/浮点数/字符串以及相关操作和赋值方法

整数(int)

​ 在Python中的整数就是包括了任意大小的整数,可以用来表示很多物理上的意义。比如1个苹果,1000块钱等等。在Python2中分成了int和long int两种。而在Python3中就只有一种整数,并且是可以取到任意大小的。

​ 常见运算:

​ 加法 : In : 5 + 2 -> Out : 7

​ 减法 : In : 3 - 1 -> Out : 2

​ 乘法 : In : 5 * 5 -> Out : 25

​ 除法 : In : 5 / 2 -> Out : 2.5

​ 乘方 : In : 3 ** 3 -> Out : 27

​ 取余 : In : 16 % 3 -> Out : 1

​ 地板数 : In : 5 // 2 -> Out : 2

浮点数(float)

​ 浮点数也就是小数,同时也可以按照科学记数法表示,如1.01e3代表这1.01 x 10的三次方。

​ 常见运算:

​ 加法 : In : 5.0 + 2.0 -> Out : 7.0

​ 减法 : In : 3.0 - 1.0 -> Out : 2.0

​ 乘法 : In : 5.0 * 5.0 -> Out : 25.0

​ 除法 : In : 5 / 2 -> Out : 2.5

​ 取余 : In : 16.0 % 3.0 -> Out : 1.0

​ 地板数 : In : 5.0 // 2.0 -> Out : 2.0

字符串

​ Python中可以用一对' '或者" "生成一个字符串,比如"hello world",可以用转义特殊字符。

​ 常见用法:

1.生成字符串

In : str = "hello world"
         print str
Out : hello world

2.字符串加法和乘法

In : str = "hello" + " world"
     print str
Out : hello world

In : str = "hello"*3
     print str
Out : hellohellohello
  1. 字符串的切割
In : str = "hello"
     print(str[0:-1])
     print(str[0])
     print(str[2:3])
     print(str[2:])
Out : hello
      hell
        ll
      llo

4.大小写转化

In : str = "hello"
     print(str)
     str = str.upper()
     print(str)
     str = str.lower()
     print(str)
Out : hello
        HELLO
        hello
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值