日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python print 函数- Python零基础入门教程

發布時間:2024/9/27 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 5

2.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 for 循環
  • Python 字符串
  • Python 列表 list
  • Python 元組 tuple
  • Python 字典 dict
  • Python 條件推導式
  • Python 列表推導式
  • Python 字典推導式
  • Python 函數聲明和調用
  • Python 不定長參數 *argc/**kargcs
  • Python 匿名函數 lambda
  • Python return 邏輯判斷表達式
  • Python 字符串/列表/元組/字典之間的相互轉換
  • Python 局部變量和全局變量
  • Python type 函數和 isinstance 函數區別
  • Python is 和 == 區別
  • Python 可變數據類型和不可變數據類型
  • Python 淺拷貝和深拷貝
  • 未經允許不得轉載:猿說編程 ? [Python print 函數]

    總結

    以上是生活随笔為你收集整理的Python print 函数- Python零基础入门教程的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。