返回列表 發帖

變數宣告與基本輸出 (一)

本帖最後由 鄭繼威 於 2022-7-18 03:02 編輯

語法
print(項目1 [,項目2 ,... (,sep=分隔字元,end=結束字
元]))
print()顯示的字串可以使用+ 進行組合,但不同型別
要先轉為文字。

  1. a=123
  2. b=456
  3. print(a,"python",b)
  4. print(a,"python",b,sep="~")
  5. print(a,"python",b,sep="~",end="!!!\n")
  6. print(str(a)+"~python~"+str(b)+"!!!")
複製代碼
Spyder 環境下常用快捷建

Ctrl+1    單行註解  
Tab    簡易智慧輸入 (輸入部分文字後按 Tab 鍵)
Ctrl+Alt+向下方向鍵    向下做單行複製
Ctrl+D    刪除單行
Ctrl+Z    回到上一步
F5    執行程式

  1. a=123
  2. b=456
  3. print(a,"python",b,)
  4. print(a,"python",b,sep="~")
  5. print(a,"python",b,sep="~",end="!!!\n")
  6. print(str(a)+"~python~"+str(b)+"!!!")
複製代碼

TOP

  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor

  4. This is a temporary script file.
  5. """
  6. a=123
  7. b=456
  8. print(a,"python",b)
  9. print(a,"python",b,sep="~")
  10. print(a,"python",b,sep="~",end="!!!\n")
  11. print(str(a)+"~python~"+str(b)+"!!!")
複製代碼

TOP

  1. a=123
  2. b=456
  3. print(a)
  4. print(a,"python",b)
  5. print(a,"ptyhon",b,sep="~")
  6. print(str(a)+"ptyhon"+str(b))
  7. print(a,"ptyhon",b,end="!!!\n")
  8. print(a,"ptyhon",b,sep="~",end="!!!")     
複製代碼

TOP

  1. a=123
  2. b=456
  3. print(a,"python",b)
  4. print(a,"python",b,sep="~")
  5. print(a,"python",b,sep="~",end="!!!\n")
  6. print(str(a)+"~python~"+str(b)+"!!!")
複製代碼

TOP

  1. a=123
  2. b=456
  3. print(str(a)+"python"+str(b))
  4. print(a,"python",b,sep="~")
  5. print(a,"python",b,sep="~",end="!!!\n")
  6. print(str(a)+"~python~"+str(b)+"!!!")
複製代碼

TOP

  1. a=123
  2. b=456
  3. #print(a,"python",b,sep="~",end="!!!\n")
  4. print(str(a)+"~python~"+str(b),end="!!!\n")
  5. print(str(a)+"~python~"+str(b),end="!!!\n")
  6. print(str(a)+"~python~"+str(b),end="!!!\n")
  7. print(str(a)+"~python~"+str(b),end="!!!\n")
  8. #print(str(a)+"~python~"+str(b),end="!!!\n")
複製代碼

TOP

返回列表