一、输出语句input    输出语句print

  例:用户输入

 username = input("username:")
#变量名 显示的字符
password = input("password:")
print(username,password)

二、格式化输出

  例:简介

 name = input("name:")         #字符型
age = input("age:")
print(type(age)) #查看age的类型 typ()输出类型
jop = input("jop:")
salary = input("salary:")

  注释:输入得到的类型是字符型,所以age得到的是字符不是数值;若使age得到的是数值应转换类型。

 age = int(input("age:"))   #age是整数型

  格式化输出四种方式

  1. 字符串的拼接
 info1 = """
------------info1 of """ +name+ '''------
Name:''' +name+ """
Age:""" +age+ '''
Jop:''' +jop+ """
Salary:""" +salary
print(info1)

  #字符串的拼接只能用于字符
  #可使用''' '''或""" """ 用于多行输出,info1已经用两种方式写出

  2. #占位符 %s 字符型,%d 十进制整数型,%f 浮点型

 info2='''
---------info2 of %s------
Name:%s
Age:%s
Jop:%s
Salary:%s
'''%(name,name,age,jop,salary) #按输出顺序写
print(info2)

  3.用  .format()    三种形式

    3.1,用变量名

 info3 = """
-----------info3 of {name2}-------
Name:{name2}
Age:{age2}
Jop:{jop2}
Salary:{salary2}
""".format(name2=name,age2=age,jop2=jop,salary2=salary) #可理解为一个数组
print(info3)

    3.2,用索引

 info4 = """
-----------info4 of {0}-------
Name:{0}
Age:{1}
Jop:{2}
Salary:{3}
""".format(name,age,jop,salary)
print(info4)

    3.3,什么都不加

1 info4 = """
2 -----------info4 of {0}-------
3 Name:{}
4 Age:{}
5 Jop:{}
6 Salary:{}
7 """.format(name,age,jop,salary)
8 print(info5)

  

三、运行结果

Python笔记(一)——打印输出的更多相关文章

  1. Python笔记之不可不练

    如果您已经有了一定的Python编程基础,那么本文就是为您的编程能力锦上添花,如果您刚刚开始对Python有一点点兴趣,不怕,Python的重点基础知识已经总结在博文<Python笔记之不可不知 ...

  2. boost.python笔记

    boost.python笔记 标签: boost.python,python, C++ 简介 Boost.python是什么? 它是boost库的一部分,随boost一起安装,用来实现C++和Pyth ...

  3. 20.Python笔记之SqlAlchemy使用

    Date:2016-03-27 Title:20.Python笔记之SqlAlchemy使用 Tags:python Category:Python 作者:刘耀 博客:www.liuyao.me 一. ...

  4. Python笔记——类定义

    Python笔记——类定义 一.类定义: class <类名>: <语句> 类实例化后,可以使用其属性,实际上,创建一个类之后,可以通过类名访问其属性 如果直接使用类名修改其属 ...

  5. 13.python笔记之pyyaml模块

    Date:2016-03-25 Title:13.Python笔记之Pyymal模块使用 Tags:Python Category:Python 博客地址:www.liuyao.me 作者:刘耀 YA ...

  6. 8.python笔记之面向对象基础

    title: 8.Python笔记之面向对象基础 date: 2016-02-21 15:10:35 tags: Python categories: Python --- 面向对象思维导图 (来自1 ...

  7. python笔记 - day8

    python笔记 - day8 参考: http://www.cnblogs.com/wupeiqi/p/4766801.html http://www.cnblogs.com/wupeiqi/art ...

  8. python笔记 - day7-1 之面向对象编程

    python笔记 - day7-1 之面向对象编程 什么时候用面向对象: 多个函数的参数相同: 当某一些函数具有相同参数时,可以使用面向对象的方式,将参数值一次性的封装到对象,以后去对象中取值即可: ...

  9. python笔记 - day7

    python笔记 - day7 参考: http://www.cnblogs.com/wupeiqi/articles/5501365.html 面向对象,初级篇: http://www.cnblog ...

  10. python笔记 - day6

    python笔记 - day6 参考: http://www.cnblogs.com/wupeiqi/articles/5501365.html 大纲: 利用递归,实现阶乘: Python反射 pyt ...

随机推荐

  1. Linq SelectMany 交叉连接

    class Student1 { public int Score { get; set; } public Student1(int score) { this.Score = score; } } ...

  2. 译《Time, Clocks, and the Ordering of Events in a Distributed System》

    Motivation <Time, Clocks, and the Ordering of Events in a Distributed System>大概是在分布式领域被引用的最多的一 ...

  3. leetcode算法:Distribute Candies

    Given an integer array with even length, where different numbers in this array represent different k ...

  4. 解决cors跨域的filter

    import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.Ordered; im ...

  5. spring boot定制Jackson ObjectMapper,为什么不生效

    先说结论: 项目中定制了spring 的redisTemplate,而这个template没有使用我自定义的Jackson ObjectMapper.所以不生效. 下面是详细过程: 起因是spring ...

  6. Python入门之函数的嵌套/名称空间/作用域/函数对象/闭包函数

    本篇目录: 一.函数嵌套 二.函数名称空间与作用域 三.函数对象 四.闭包函数 ============================================================ ...

  7. 如何用elementui去实现图片上传和表单提交,用axios的post方法

    下面是在vue搭建的脚手架项目中的组件component文件夹下面的upload.vue文件中的内容 <!--这个组件主要用来研究upload这个elementui的上传插件组件--> & ...

  8. Ubuntu Sublime 配置

    p { margin-bottom: 0.25cm; line-height: 120% } a:link { } 2018.4.14 Ubuntu Sublime 配置 承 Ubuntu Apach ...

  9. 10_Python函数方法加深_Python编程之路

    上节课已经简单的跟大家讲了如何定义一个方法,但是并没有深入去讲,这一节我们继续来学习定义方法中需要注意的几点 默认参数 前面我们讲到定义一个方法时是可以传递参数的,除了这个功能,实际上python在定 ...

  10. [LeetCode] Baseball Game 棒球游戏

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...