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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

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

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

2.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)

四.猜你喜歡

  • Python for 循環(huán)
  • Python 字符串
  • Python 列表 list
  • Python 元組 tuple
  • Python 字典 dict
  • Python 條件推導(dǎo)式
  • Python 列表推導(dǎo)式
  • Python 字典推導(dǎo)式
  • Python 函數(shù)聲明和調(diào)用
  • Python 不定長參數(shù) *argc/**kargcs
  • Python 匿名函數(shù) lambda
  • Python return 邏輯判斷表達(dá)式
  • Python 字符串/列表/元組/字典之間的相互轉(zhuǎn)換
  • Python 局部變量和全局變量
  • Python type 函數(shù)和 isinstance 函數(shù)區(qū)別
  • Python is 和 == 區(qū)別
  • Python 可變數(shù)據(jù)類型和不可變數(shù)據(jù)類型
  • Python 淺拷貝和深拷貝
  • 未經(jīng)允許不得轉(zhuǎn)載:猿說編程 ? [Python print 函數(shù)]

    總結(jié)

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

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。