ATM机交互
-
插卡
-
输入密码
-
选择功能
-
存款
1 Python的与用户交互
input('请输入瑞星卡号')
input('输入密码')
请输入瑞星卡号5201314
输入密码15236
'15236'
print('*'*100)
****************************************************************************************************
print('*'*100)
input('请插入瑞星卡')
print('_'*100)
****************************************************************************************************
请插入瑞星卡25
____________________________________________________________________________________________________
input 只是一个过渡阶段
vip_card = input('please input VIP card')
print(vip_card)
please input VIP cardasdfghjkl;
asdfghjkl;
print(vip_card)
print(id(vip_card))
print(type(vip_card))
asdfghjkl;
2263780973424
<class 'str'>
无论你输入什么类型,input接受的都是字符串
age = input('请输入你的年龄')
print(age)
print(type(age))
age = int(age)
请输入你的年龄23
23
<class 'str'>
age = age + 1
print(age)
24
2 格式化输出
age = input('age:>>>')
print('My age is '+ age)
age:>>>23
My age is 23
age = input('age:')
print('My age is',age)
age:23
My age is 23
name = input('name:')
height = input('height:')
age = input('age:')
print('My age is ',age,',My name is',name,',My height is',height)
name:xk
height:185
age:23
My age is 23 ,My name is xk ,My height is 185
2.1 占位符
name = input('name:')
height = input('height:')
age = input('age:')
print('My name is %s. My age is %s, My height is %s'%(name,age,height))
name:1
height:1
age:1
My name is 1. My age is 1, My height is 1
name = input('name:')
height = input('height:')
height = int(height)
age = input('age:')
age = int(age)
print('My name is %s. My age is %d, My height is %d'%(name,age,height))
name:xc
height:1
age:1
My name is xc. My age is 1, My height is 1
format格式化
name = input('name:')
height = input('height:')
age = input('age:')
print('My name is {}. My age is {}, My height is {}'.format(name,age,height))
name:xk
height:185
age:23
My name is xk. My age is 23, My height is 185
f-string格式化
name = input('name:')
height = input('height:')
age = input('age:')
print(f'My name is {name}. My age is {age}, My height is {height}')
name:xk
height:23
age:185
My name is xk. My age is 185, My height is 23
print(f'My name is {name}. My age is {int(age)+1}, My height is {height*10}')
My name is xk. My age is 186, My height is 23232323232323232323
print(f'My name is {name}. My age is {int(age)+1:.5f}, My height is {height*10}')
My name is xk. My age is 186.00000, My height is 23232323232323232323
print(f'My name is {"name"}. My age is {int(age) + 1}, My height is {height*10}')
My name is name. My age is 186, My height is 23232323232323232323
基本运算符
算术运算符
比较运算符
赋值运算符
逻辑运算符
身份运算符
算术运算符 加减乘除
比较运算符 大于小于大于等于小于等于 恒等于不等于
#赋值运算符
x = 2
print(x)
2
#逻辑运算符
#and,or,not
1 <= 1 and 1>=1
True
1 <= 1 or 1>1
True
not'sadsads'
False
#身份运算符 比较的是id
x = 10
y = 10
print(x is y)
True
x = 257
y = 257
print(x is y)
False
x = 10
y = 11
print (x is y)
print(x == y)
False
False
is比较的是id,==比较的是值
python运算符优先级
1*3 > 2*1
True
链式赋值(重要)
x = 10
y = 10
z = 10
print(x,y,z)
10 10 10
x,y,z = 10,10,10
print(x,y,z)
10 10 10
交叉赋值
x = 10
y = 20
z = x
x = y
y = z
print(x,y,z)
20 10 10
x = 10
y = 20
x,y = y,x
print(x,y)
20 10
解压缩
hobby_list = ['reading','666','2333']
print(hobby_list[2])
2333
hobby_list = ['reading','666','2333']
hobby1,hobby2,hobby3 = hobby_list
print(hobby1)
print(hobby2)
rading
666
hobby_list = ['reading','666','2333','999']
_,hobby1,_,hobby2 = hobby_list
print(hobby1)
print(hobby2)
666
999
hobby_list = ['reading','666','2333','999','reading','666','2333','999']
hobby1,*_,hobby2 = hobby_list
print(hobby1)
print(hobby2)
reading
999
标签:name,2024.8,age,height,print,input,My
From: https://www.cnblogs.com/shalatia/p/18354450