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