python 学习 2

一、python的内置函数

1.求平方:pow()   

2.求绝对值:abs()   

3.将浮点数圆整为与之最接近的整数,若一样则圆整到偶数: round()   地板除是总向下圆整

二、模块

math模块

1.将其转化为整数,向下取整:floor()

>>> math.floor(3.3)
3.0
>>> math.floor(3.9)
3.0

2.将其转为整数,返回大于或者等于给定数的最小整数:ceil()

>>> math.ceil(3.9)
4.0
>>> math.ceil(3.2)
4.0

cmath模块

是复数模块

turtle模块

绘制心形

from turtle import *
import turtle
pensize(2)
pencolor('red')
fillcolor('pink')
speed(10)
up()
goto(-30,100)
down()
begin_fill()
left(90)
circle(120,180)
circle(360,70)
left(38)
circle(360,70)
circle(120,180)
end_fill()
up()
goto(-100,100)
down()

三、字符串‘str’和‘repr’

str:可以转化为用户能够看懂的字符串

repr:原始字符串

>>> print(repr("hello,\nworld"))
'hello,\nworld'
>>> print(str("hello,\nworld"))
hello,
world
>>>

原始字符串的前缀可以用 r 表示,不可以用单个反斜杠结尾,若必须以反斜杠结尾,就用\将其转义

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值