返回列表 發帖

資料型態轉換

  1. a=b="20"
  2. print("a="+a)
  3. print("b="+b)
  4. c=a+b
  5. d=int(a)+int(b)
  6. print("字串相加: "+c)
  7. print("數字相加: "+str(d))
複製代碼

  1. a=b=20  #int
  2. c=d="20" #str

  3. print("a={}".format(a))
  4. print(f"b={b}")

  5. e=c+d
  6. print("字串相加="+e)

  7. f=int(c)+int(d)
  8. print("數字相加="+str(f))
複製代碼

TOP

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

  4. This is a temporary script file.
  5. """
  6. a=b="20"
  7. print("a="+a)
  8. print("b="+b)
  9. c=a+b
  10. d=int(a)+int(b)
  11. print("字串相加:"+c)
  12. print("字串相加:"+str(d))
複製代碼

TOP

  1. a=b="20"
  2. print("a="+a)
  3. print("b="+b)
  4. c=a+b
  5. d=int(a)+int(b)
  6. print("字串相加: "+c)
  7. print("數字相加: "+str(d))
複製代碼

TOP

  1. a=b=20
  2. print(f"a={a}")
  3. print(f"b={b}")
  4. c=a+b
  5. d=int(a)+int(b)
  6. print(f"字串相加={d}")
複製代碼

TOP

  1. a="20"
  2. b="20"
  3. print("a="+a)
  4. print("b="+b)
  5. c=a+b
  6. d=int(a)+int(b)
  7. print("字串相加="+c)
  8. print("數字相加="+str(d))
複製代碼

TOP

  1. c=d="20"
  2. e=c+d
  3. f=int(c)+int(d)
  4. print("自串組合="+(e))
  5. print("數字組合="+str(f))
複製代碼

TOP

返回列表