put("Age:"))
Job=input("Job:")
Salary=float(input("Salary:"))
info='''
----------------info of %s------------------
Name:%s
Age:%d
Job:%s
Salary:%f
''' % (Name,Name,Age,Job,Salary)
print(info)
====================================================================
G:\Python3.7.3\python.exe G:/practise/oldboy/day1/interaction.py
name:chennjisong
Age:23
Job:IT
Salary:1888
----------------info of chennjisong------------------
Name:chennjisong
Age:23
Job:IT
Salary:1888.000000
Process finished with exit code 0
解释:红色部分为数据类型的强制转换,绿色部分为输入的变量
字符串拼接第三种方法(format):
#!/usr/bin/env python
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: interaction.py
@time: 2019/04/15
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
Name=input("name:")
Age=int(input("Age:"))
Job=input("Job:")
Salary=float(input("Salary:"))
info='''
----------------info of {_Name}------------------
Name:{_Name}
Age:{_Age}
Job:{_Job}
Salary:{_Salary}
''' .format(_Name=Name,_Age=Age,_Job=Job,_Salary=Salary)
print(info)
=============================================================================================
G:\Python3.7.3\python.exe G:/practise/oldboy/day1/interaction.py
name:chenjisong
Age:23
Job:IT
Salary:289
----------------info of chenjisong------------------
Name:chenjisong
Age:23
Job:IT
Salary:289.0
Process finished with exit code 0
解释:将变量与值形成一一对应的关系
字符串拼接第四种方法(花括号):
#!/usr/bin/env python
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: interaction.py
@time: 2019/04/15
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
Name=input("name:")
Age=int(input("Age:"))
Job=input("Job:")
Salary=float(input("Salary:"))
info='''
----------------info of {0}------------------
Name:{0}
Age:{1}
Job:{2}
Salary:{3}
''' .format(Name,Age,Job,Salary)
print(info)
=============================================================================================
G:\Python3.7.3\python.exe G:/practise/oldboy/day1/interaction.py
name:chenjisong
Age:28
Job:IT
Salary:2900
----------------info of chenjisong------------------
Name:chenjisong
Age:28
Job:IT
Salary:2900.0
Process finished with exit code 0
将变量换成花括号中的位置参数,并在format后面指明变量
第一周-第11章节-Python3.5-if else流程判断
最简单的逻辑判断:
#!/usr/bin/env python
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: getpass.py
@time: 2019/04/15
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
_username = "chenjisong"
_password = "chenjisong123"
username = input("Name:")
password = input("Password:")
if _username==username and _password==password:
print("Welcome user {name} login ...".format(name=username))
else:
print("Invalid username or password.")
=====================================================================================
两种结果:
条件不符合:
"G:\Python 3.6.6\python.exe" G:/practise/oldboy/day1/getpass.py
Name:cjs
Password:123
Invalid username or password.
Process finished with exit code 0
条件符合:
"G: