写博客真麻烦python学习笔记

'''cars = ['audi','bmw','subaru','toyota']

for car in cars:
if car == 'bmw':
print(car.upper())
else:
print(car.title())

requsted_topping = 'mushrooms'
if requsted_topping != 'anchovies':
print('Hold the anchovies!')

'''

'''
#while xStr非空
#将xStr转换为数字x
#将x加入sum
#count值加1
#接受下个字符串数据,xStr
#
def main():
sum = 0.0
count = 0
_x = input('Enter a number (<Enter> to quit) > >')
while _x != "":
x = eval(_x)
sum = sum + x
count += 1
_x = input('Enter a numver (negative to quit)>>')
print('\n The average of the number is ',sum/count)
main()

'''
#三原运算
a,b,c = 1,3,5
d = a if a>b else c

if a>b : d = a
else :d = c
'''
二进制,01
八进制 ,012345678
十六进制0123456789abcdef #H后缀 0x前缀 每四个二进制表示一个16进制数
'''
#encode 编码 decode 解码

message = '我爱我家'
print(message)
print(message.encode()) #括号里默认utf-8
print(message.encode(encoding='utf-8').decode(encoding='utf-8'))

cj = '是个大狗屎'
print(cj.encode())


#print(names)
#print(names.index('...')) 查看。。。在列表中的位置
#print( names[names.index('...')] ) 打印列表中。。。的名字
#print(names.count('...')) 计数列表中。。。的数量
#names.extend() 把列表扩展到names 扩展的列表还在

print('fuck off'.encode())
____o='fuck off'
print(____o.encode())

#把字符串改成二进制

def encode(s):
return ' '.join([bin(ord(c)).replace('0b', '') for c in s])

def decode(s):
return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]])
print(encode(cj))

猜你喜欢

转载自www.cnblogs.com/1000001000python/p/10581103.html