返回列表 發帖

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

本帖最後由 鄭繼威 於 2024-1-24 14:13 編輯

語法
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. c=0.15
  4. d="apple"
  5. z=a+b
  6. a=a+1
  7. a=str(a)

  8. #輸出
  9. print("a=",a,"b=",b,"c=",c,sep='~',end='\n')
  10. print("d=",d,"z=",z)
  11. print("d="+d)
  12. print("a=",a,sep='',end="!!!aaaaaaa\n")
  13. print("a="+str(a))
複製代碼

TOP

  1. a=1
  2. b=a+1
  3. c=b+1
  4. d=c+1
  5. e=d+1
  6. f=e+1
  7. g=e+1
  8. h=g+1
  9. i=h+1
  10. j=i+1
  11. k=j+1
  12. l=k+1
  13. m=l+1
  14. n=m+1
  15. o=n+1
  16. p=o+1
  17. q=p+1
  18. r=q+1
  19. s=r+1
  20. t=s+1
  21. u=t+1
  22. v=u+1
  23. w=v+1
  24. x=w+1
  25. y=x+1
  26. z=y+1
  27. print(a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z)
複製代碼

TOP

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

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(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(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(a,"lol",b)
  4. print(a,"lol",b,sep="")
  5. print(a,"lol",b,end="bruh")
  6. print(str(a)+"lol"+str(b)+"32")
複製代碼

TOP

  1. a=11111
  2. b=3.14159265358978323846
  3. c='banana'
  4. s=a-b
  5. w=s+a+b
  6. print(a,s,b,sep='g',end='uuuuyyyyyyyyyy7t8uigtuigk')
  7. print(w,c,sep='43684854545619797797865536',end='kljoiuomgftrxw25743\n)
  8. print(a,b,z,c,w,sep='3.14159265358979323846',end='---------------------------',file=sys.stdout,flush=false)
複製代碼

TOP

  1. a=1
  2. b=1.5
  3. c="apple"
  4. print(str(a)+str(b)+c,end=(__))
  5. print("a=",a,"b=",b,"c="+"apple",sep="_")
複製代碼

TOP

  1. a=b=c=20
  2. a=1
  3. b=0.2
  4. c=1.2
  5. d=2.3
  6. e=3.0
  7. f=0.09
  8. g=h=i=30
複製代碼

TOP

name="劉乙頡"
age="200"
print("mynameis"+name+"im"+age+"yearsold")

TOP

a=98
b=89
print(a,"python",b)
print(a,"python",b,sep="~")
print(a,"python",b,sep="~",end="!!!\n")
print(str(a)+"~python~"+str(b)+"!!!")

TOP

返回列表