print('aa\
h')
a=10
b=20
c=999999999999999999999999999999999999999999999999999999999999
d=45**10
e = 123_45_45
f = 0.1+0.2
s = 'hello'
s = "hello"
s = '子曰:"学而时习之"'
s = 'ggggg,\
kkkkkkk'
s = '''hhhh,
wwww'''
s = '子曰:\'学而时习之\''
a = 123
b = 'aaa' + 'kkk' + '好好'
b = 'Hello %s'%'孙悟空'
b = 'hello %s 你好 %s'%('tom','孙悟空')
b = 'hello %3.5s'%'abcdefg'
b = 'hello %s'%123.456
b = 'hello %.2f'%123.456
b = 'hello %d'%123.95
b = '呵呵'
c = f'hello {a} {b}'
print(f'a = {a}')
a = 'abc'
a = a * 20
print(a)
b = None
print(b)
a = 123
b = '123'
c = type('123')
c = type(a)
print(type(1))
print(type(1.5))
print(type(True))
print(type('hello'))
print(type(None))
a = False
a = int(a)
a = '123'
a = int(a)
a = 11.6
a = int(a)
a = '11.5'
a = None
a = 1
a = float(a)
a = False
a = float(a)
a = 123
a = str(a)
a = None
a = bool(a)
print('a =',a)
print('a的类型是',type(a))
a = True
a = not a
a = 1
a = ''
a = not a
result = True and True
result = True and False
result = False and True
result = False and False
result = True or True
result = True or False
result = False or True
result = False or False
result = 1 and 2
result = 1 and 0
result = 0 and 1
result = 0 and None
result = 1 or 2
result = 1 or 0
result = 0 or 1
result = 0 or None
print(result)
a = 30
b = 50
max = a if a > b else b
print(max)
if False :
print(123)
print(456)
print(789)
print(101112)
age = 7
if age > 17 :
print('你已经成年了~~')
else :
print('你还未成年~~')
age = 68
if age >= 18 and age < 30 :
print('你已经成年了!')
elif age >= 30 and age < 60 :
print('你已经中年了!')
elif age >= 60 :
print('你已经退休了!')
i = 0
while i < 10 :
i += 1
print(i,'hello')
else :
print('else中的代码块')
i = 0
if i < 5:
pass
my_list = []
my_list = [10]
my_list = [10,20,30,40,50]
my_list = [10,'hello',True,None,[1,2,3],print]
my_list = [10,20,30,40,50]
print(len(my_list))
stus = ['孙悟空','猪八戒','沙和尚','唐僧','蜘蛛精','白骨精']
print(stus[::-1])
my_list = [1,2,3] + [4,5,6]
my_list = [1,2,3] * 5
stus = ['孙悟空','猪八戒','沙和尚','唐僧','蜘蛛精','白骨精','沙和尚','沙和尚']
arr = [10,1,2,5,100,77]
print(stus.count('牛魔王'))
stus = ['孙悟空','猪八戒','沙和尚','唐僧','蜘蛛精','白骨精']
stus[0] = 'sunwukong'
stus[2] = '哈哈'
del stus[2]
stus = ['孙悟空','猪八戒','沙和尚','唐僧','蜘蛛精','白骨精']
s = 'hello'
s = list(s)
print(s)
stus = ['孙悟空','猪八戒','沙和尚','唐僧']
my_list = list('asnbdnbasdabd')
my_list = [10,1,20,3,4,5,0,-2]
print('修改前',my_list)
my_list.sort(reverse=True)
print('修改后',my_list)
for s in stus :
print(s)
r = range(5)
r = range(0,10,2)
r = range(10,0,-1)
for i in range(30):
print(i)
my_tuple = ()
my_tuple = (1,2,3,4,5)
my_tuple = 10,20,30,40
my_tuple = 40,
my_tuple = 10 , 20 , 30 , 40
a,b,c,d = my_tuple
a = 100
b = 300
a , b = b , a
my_tuple = 10 , 20 , 30 , 40
a , b , *c = my_tuple
a , *b , c = my_tuple
*a , b , c = my_tuple
a , b , *c = [1,2,3,4,5,6,7]
a , b , *c = 'hello world'
print('a =',a)
print('b =',b)
print('c =',c)
a = [1,2,3]
b = a
b = [10,2,3]
a = [1,2,3]
b = [1,2,3]
print(a,b)
print(id(a),id(b))
print(a == b)
print(a is b)
d = {}
d = {
'name':'孙悟空' ,
'age':18 ,
'gender':'男' ,
'name':'sunwukong'
}
d = dict(name='孙悟空', age=18, gender='男')
d = dict([('name', '孙悟饭'), ('age', 18)])
d = dict(name='孙悟空', age=18, gender='男')
d['name'] = 'sunwukong'
d['address'] = '花果山'
result = d.setdefault('name', '猪八戒')
result = d.setdefault('hello', '猪八戒')
d = {'a': 1, 'b': 2, 'c': 3}
d2 = {'d': 4, 'e': 5, 'f': 6, 'a': 7}
d.update(d2)
del d['a']
del d['b']
result = d.pop('d')
result = d.pop('z', '这是默认值')
d.clear()
d = {'a': 1, 'b': 2, 'c': 3}
d2 = d.copy()
d = {'a': {'name': '孙悟空', 'age': 18}, 'b': 2, 'c': 3}
d2 = d.copy()
d2['a']['name'] = '猪八戒'
print('d = ', d, id(d))
print('d2 = ', d2, id(d2))
此博客仅用于博主学习记录过程
转载请注明原文地址:https://ipadbbs.8miu.com/read-53591.html