设为首页 加入收藏

TOP

python学习第一天 -----2019年4月15日(四)
2019-05-23 16:08:28 】 浏览:74
Tags:python 学习 第一 -----2019年 4月 15日
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:

首页 上一页 1 2 3 4 5 6 下一页 尾页 4/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇周末学习笔记——day01(函数,函.. 下一篇数据结构(三):队列

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目