python

1. 一些以前不知道的

1. //

9//3 :输出是3,//表示取整

2. 三引号’’’

s = '''
This is the first line
    This is the second line
'''
print(s)

结果为
在这里插入图片描述

3. +

  • 两边是数字,相加
  • 两边是字符串,连接
a = str(98.6)
a + "2"

结果为'98.62'

4. Shift+回车

  • 一直向下运行代码

5. slice

letters = "abcdefghijklmnopqrstuvwxyz"
letters[0]

输出为'a'

letters = "abcdefghijklmnopqrstuvwxyz"
letters[0]

输出为‘a’

若为letters[-2],输出为‘安’
若为letters[:],输出为'我爱北京天安门'
若为letters[2:],输出为'北京天安门'
若为letters[-3:],输出为'天安门'
若为letters[:5],输出为'我爱北京天'
若为letters[:100],输出为'我爱北京天安门'
若为letters[2:5],输出为'北京天'
若为letters[1:2:5],输出为'爱'
若为letters[-6:-2],输出为'爱北京天'

6.split和combine

  • 默认空格切分
lan = "python ruby c c++ swift"
lan.split()

输出['python', 'ruby', 'c', 'c++', 'swift']

  • 按空格切
todos = "download python, install, download ide, learn"
todos.split(', ')

输出为:['download python', 'install', 'download ide', 'learn']

  • join
','.join(['download python', 'install', 'download ide', 'learn'])

输出:'download python,install,download ide,learn'

7. replace

s = 'I like C. I like C++. I like Python'
s.replace('like', 'hate')

输出:'I hate C. I hate C++. I hate Python'

s.replace('like', 'hate', 1)

输出:'I hate C. I like C++. I like Python'

8. find

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值