Python print 函数- Python零基础入门教程
生活随笔
收集整理的這篇文章主要介紹了
Python print 函数- Python零基础入门教程
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
- 一.Python print 函數(shù)簡介
- 二.Python print 函數(shù)語法
- 三.Python print 函數(shù)使用
- 1.objects 參數(shù)
- 2.sep 參數(shù)
- 3.end 參數(shù)
- 4.flush 參數(shù)
- 四.猜你喜歡
零基礎(chǔ) Python 學(xué)習(xí)路線推薦 : Python 學(xué)習(xí)目錄 >> Python 基礎(chǔ)入門
一.Python print 函數(shù)簡介
Python 中內(nèi)置函數(shù)我們使用的最頻繁的莫過于 print 函數(shù),重 helloword 開始,我們就一直在接觸 print ,雖然使用簡單,不過你真的會玩 print 函數(shù)嗎??
二.Python print 函數(shù)語法
語法介紹:
‘’‘ 參數(shù)介紹:objects — 復(fù)數(shù),表示可以一次輸出多個對象。輸出多個對象時,需要用 , 分隔;sep — 用來間隔多個對象,默認(rèn)值是一個空格end — 用來設(shè)定以什么結(jié)尾。默認(rèn)值是換行符 \n,我們可以換成其他字符串;flush — 輸出是否被緩存通常決定于 file,但如果 flush 關(guān)鍵字參數(shù)為 True,流會被強(qiáng)制刷新;返回值:無; ’‘’print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)三.Python print 函數(shù)使用
1.objects 參數(shù)
使用內(nèi)置函數(shù) print 可以同時輸出多個對象,例如:
print(1,2,3,4,5) # 1 2 3 4 52.sep 參數(shù)
在使用 print 函數(shù)同時輸出多個對象時,默認(rèn)都是以空格隔開,我們同樣可以修改參數(shù) sep ,自定義字符隔開對象,例如:
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python print 函數(shù).py @Time:2021/04/26 07:37 @Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!"""print(1,2,3,4,5,sep="*") print(1,2,3,4,5,sep="$") print(1,2,3,4,5,sep="g") print(1,2,3,4,5,sep="你大爺") print(1,2,3,4,5,sep="猿說python")''' 輸出結(jié)果:1*2*3*4*5 1$2$3$4$5 1g2g3g4g5 1你大爺2你大爺3你大爺4你大爺5 1猿說python2猿說python3猿說python4猿說python5 '''3.end 參數(shù)
默認(rèn) print 函數(shù)輸出結(jié)束之后會自動換行,當(dāng)我們不想換行的時候怎么辦?可以直接通過修改 end 參數(shù)完成,例如:
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python print 函數(shù).py @Time:2021/04/26 07:37 @Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!"""for i in range(5):print(i) # 默認(rèn)換行print("***"*20)for i in range(5):print(i,end=" ") # 默認(rèn)以空格隔開''' 輸出結(jié)果: 0 1 2 3 4 ************************************************************ 0 1 2 3 4 '''4.flush 參數(shù)
默認(rèn)該值為 False ,如果設(shè)置為 True ,輸出流默認(rèn)會被強(qiáng)制刷新,例如:
# !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿說編程 @Blog(個人博客地址): www.codersrc.com @File:Python print 函數(shù).py @Time:2021/04/26 07:37 @Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!"""import time# 默認(rèn)flush為False print("Loading",end = "") for i in range(6):print(".",end = '')time.sleep(0.5)# 換行 print("",end="\n") print("***"*20,end='\n')# flush設(shè)置為True print("Loading",end = "") for i in range(6):print(".",end = '',flush = True)time.sleep(0.5)四.猜你喜歡
未經(jīng)允許不得轉(zhuǎn)載:猿說編程 ? [Python print 函數(shù)]
總結(jié)
以上是生活随笔為你收集整理的Python print 函数- Python零基础入门教程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python min 函数 - Pyth
- 下一篇: websocket python爬虫_p