python进阶第一课:常规函数

#简单python操作函数
# del函数

'''
motorcycles =['honda','yamaha','suzuki']
print(motorcycles)
del motorcycles[0]

print(motorcycles)

#append函数
motorcycys=[]
motorcycys.append('honda')
motorcycys.append('yamaha')
motorcycys.append('yamaha')

print(motorcycys)


#insert 函数
motorcycles.insert(0,'ducati')
print(motorcycles)

# pop函数:删除列表末尾元素
motorcycles1 = ['honda','yamaha','suzuki','xiaoyu']

print(motorcycles1)
popped_motorcycles1 = motorcycles1.pop()
print(motorcycles1)
print(popped_motorcycles1)

# pop函数:删除列表任意元素(与del的区别在于删除的元素还要不要用)

motorcycles1 = ['honda','yamaha','suzuki','xiaoyu']

print(motorcycles1)
popped_motorcycles1 = motorcycles1.pop(1)
print(motorcycles1)
print(popped_motorcycles1)

#remove函数,从列表中删除某值但是不知道其索引,只删除第一个指定的值
motorcycles1 = ['honda','yamaha','suzuki','xiaoyu','suzuki']
print(motorcycles1)
motorcycles1.remove('suzuki')
print(motorcycles1)

#sort 函数,对列表进行永久排序(字符倒叙正序)
cars = ['bmw','audi','toyota','subaru']
print(cars)
cars.sort()
print(cars)
cars.sort(reverse=True)
print(cars)
'''
#sorted()对列表进行临时排序 len计数是从1开始
cars = ['bmw','audi','toyota','subaru']
print(cars)
print(sorted(cars))
print(cars)
cars.reverse()
print(cars)
print(len(cars))


>>> ablum =['black star,'zhou jian',25,True]
        
SyntaxError: invalid syntax
>>> ablum =['black star','zhou jian',25,True]
        
>>> ablum.append('new song')
        
>>> print(ablum[0],ablum[-1])
        
black star new song
>>> 'black star' in ablum
        
True
>>> the_end ='eddie'
        
>>> name ='eddie'
        
>>> the_end == name
        
True
>>> the_end is name
        
True
>>> bool(0)
        
False
>>> bool([])
        
False
>>> bool('')
        
False
>>> bool(False)
        
False
>>> bool(None)
        
False
>>> bool(20)
        
True
>>> a_thing =None
        
>>> print(a_string)
        
Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    print(a_string)
NameError: name 'a_string' is not defined
>>> print(a_thing)
        
None
>>> 1<3 and 2<5
        
True
>>> 2<3 or 3<1
        
True
>>> 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值