1.打印多个参数
用逗号隔开:
>>> print('Age:', 42)
Age: 42
参数之间自动插入了一个空格字符
>>> name = 'Gumby'
>>> salutation = 'Mr.'
>>> greeting = 'Hello,'
>>> print(greeting, salutation, name)
Hello, Mr. Gumby
如果greeting中不包含逗号,可以这样:
print(greeting + ',', salutation, name)
可以自定义分隔符
>>> print("I", "wish", "to", "register", "a", "complaint", sep="_")
I_wish_to_register_a_complaint
也可以自定义结束字符串,默认为换行符
print('Hello,', end='')
print('world!')
上述代码打印Hello, world!
 
2.导入时重命名
从模块导入,有以下几种方式
import somemodule
from somemodule import somefunction
from somemodule import somefunction, anotherfunction,yetanotherfunction
from somemodule import *
当两个模块都包含函数open,可以用第一种方式导入并这样使用:
module1.open(...)
module2.open(...)
也可以这样用as指定别名
下边是模块的别名
>>> import math as foobar
>>> foobar.sqrt(4)
2.0
下边是函数别名
>>> from math import sqrt as foobar
>>> foobar(4)
2.0
 

Python-8-print和import进阶的更多相关文章

  1. Python之路,Day16 - Django 进阶

    Python之路,Day16 - Django 进阶   本节内容 自定义template tags 中间件 CRSF 权限管理 分页 Django分页 https://docs.djangoproj ...

  2. Python爬虫与数据分析之进阶教程:文件操作、lambda表达式、递归、yield生成器

    专栏目录: Python爬虫与数据分析之python教学视频.python源码分享,python Python爬虫与数据分析之基础教程:Python的语法.字典.元组.列表 Python爬虫与数据分析 ...

  3. Python之print()函数

    1. 输出字符串 >>> str = 'Hello World' >>> print (str) Hello World 2. 格式化输出整数 支持参数格式化 &g ...

  4. python笔记-1(import导入、time/datetime/random/os/sys模块)

    python笔记-6(import导入.time/datetime/random/os/sys模块)   一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...

  5. python3入门之print,import,input介绍

    本节主要介绍print,import和input,t函数,包括他们在python2.7和python3 的区别以及用法.下面附有之前的文章: ​ python3的print函数的变化 python3之 ...

  6. Python之print详解

    Python之print详解 http://www.jb51.net/article/55768.htm   print的一些基本用法,在前面的讲述中也涉及一些,本讲是在复习的基础上,尽量再多点内容. ...

  7. Python中print用法里面% ,"%s 和 % d" 代表的意思

    Python 编程 里面% . "%s 和 % d" 代表的意思 %s,表示格化式一个对象为字符 %d,整数 "Hello, %s"%"zhang3& ...

  8. Python将print输出内容保存到指定文件中

    #!/usr/bin/python # -*- coding: utf- -*- import sys import os class Logger(object): def __init__(sel ...

  9. python中print后面加逗号

    python中print输出一行,如果想多次输出的内容不换行,可以在print后面加逗号 例如 每个输出一行 phrase = "abcdefg" # Add your for l ...

  10. python中print()函数的“,”与java中System.out.print()函数中的“+”

    python中的print()函数和java中的System.out.print()函数都有着打印字符串的功能. python中: print("hello,world!") 输出 ...

随机推荐

  1. 1--单独使用jdbc开发问题总结

    1.数据库连接,使用时就创建,不使用立即释放,对数据库进行频繁连接开启和关闭,造成数据库资源浪费,影响 数据库性能. 设想:使用数据库连接池管理数据库连接. 2.将sql语句硬编码到java代码中,如 ...

  2. axios无法在ie9,10,11环境下运行的问题解决

    npm install es6-promise --save-dev import promise from 'es6-promise'; promise.polyfill();

  3. POJ 2151 Check the difficulty of problems:概率dp【至少】

    题目链接:http://poj.org/problem?id=2151 题意: 一次ACM比赛,有t支队伍,比赛共m道题. 第i支队伍做出第j道题的概率为p[i][j]. 问你所有队伍都至少做出一道, ...

  4. 读《nodejs开发指南》记录

    最近看了一下<nodejs开发指南>发现nodejs在某些特定的领域由他自己的长处,适合密集计算但是业务逻辑比较简单的场景,如果做网站还是选择php吧,呵呵,这本书我除了第5章<用n ...

  5. LoadRunner监控图表与配置(二)监控运行状况和交易状况

    1.在左侧Available Graphs视图中展开Runtime Graphs节点,选择其中一种类型添加至控制器运行标签的界面. 2.在图中显示的空白区域点击右键,在弹出的快捷菜单中选择config ...

  6. L95

    The children squealed with delight when they saw the puppy.The signal will be converted into digital ...

  7. Hotel California

    On a dark desert highway行驶在昏黑的荒漠公路上cool wind in my hair凉风吹过我的头发warm smell of colutas温馨的大麻香rising up ...

  8. erlang的map基本使用

    maps 适用于需要在运行时改变数据结构(record则不行)的场景,可以动态增加key 数据量不宜过大,具体多大没有实际数据, maps from_list  如果list表很长,则相应的耗时时间会 ...

  9. MySQL left join 20161024

    公司OA系统上部门上线了一套流程,总部和分公司部门提数据需求都要走线上流程,审批,想想也是不错的,能和绩效更加合理的挂钩,还有打分评价,双向互动. 下午接到一个需求,查看某分公司上周订单使用优惠券情况 ...

  10. 【Lintcode】029.Interleaving String

    题目: Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2 ...