内部功能

变量的命名规则
1、变量名只能是字母、数字或下划线的任意组合
2、变量名的第一个字符不能是数字
Python2 Python3
input() eval(input())
raw_input() input()
3、某些关键字不能声明为变量名

这里写图片描述

元组的元素不可修改,元组的元素的元素可以被修改

age = 18
age.bit_length()     5     二进制最少占几位
bin(18)          '0b10010'
abs(-18)    18    绝对值
age.__abs__()     18    绝对值
age.__add__(100)     118
all_item = 95
pager = 10
result = all_item.__divmod__(pager)
print(result)                                 (9, 5)     分页的时候可以用到
age. __rdivmod__(7)     7/18                 (0, 7)  (商,余数)
a = 5
result1 = a.__floordiv__(6)
print(result1)
print(5//6)                                        0,0    地板除
name='eric'
print(type(name))     name的数据类型
print(dir(name))      快速获取这个类里边提供了那些成员
print(vars(name)     快速获取这个类里边提供了那些成员以及成员值
name = str(‘eric’)    默认执行__init()__方法
result = name.__contains__("er")
getattribute  反射
result = name.center(20,'*')         ********eric********
name = "alex {0} as {1}"
result = name.format('sb','eric')
print(result)                       alex sb as eric
name = "alex {name} as {id}"
result = name.format(name='sb',id='eric')
print(result)                      alex sb as eric
li = ['s','a','b']
result = "_".join(li)                 s_a_b
name = 'dandan'
result = name.partition('an')         ('d', 'an', 'dan')
name = 'dandan'
result = name.replace('an','oo'1)            doodan
name = """
da
shu
ba"""
result = name.splitlines()                    ['', 'da', 'shu', 'ba']
result = name.split('\n')
swapcase   小写转大写,大写转小写dic = dict(k1='v1',k2='v2')
new = dic.fromkeys(['k1','k2','k3'],'v1')
print(new)
print(dic['k1'])
print(dic['k2'])
print(dic['k3'])
print(dic.get('k1'))
print(dic.get('k2'))
print(dic.get('k3'))
dic['k3'] = 123
dic.setdefault('k4')
print(dic)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值