程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

F1- sum of two numbers -python output

編輯:Python

1. % The way

""" author:claire data:2022 year 06 month 23 title: Sum of two numbers """
num1 = 1.5
num2 = 3.8
sum = num1+num2
print("%f + %f = %f" % (num1,num2,sum ))

Pay attention to what
The front is %f %d such
No comma after , after % There should be commas inside

format function

format() The function is mainly used to format strings

pycharm Comment lines ctrl+/

str = " My name is {}, My nationality is {}".format(" Zhang San "," China ")
print(str)
str = " My name is {0}, My nationality is {1}".format(" Zhang San "," China ")
print(str)
str = " My name is {1}, My nationality is {0}".format(" Zhang San "," China ")
print(str)

3. Keyword filling

print(" The websites :{name}, Address {url}".format(name="cc",url="123"))

4. Set the parameters through the dictionary , use ** an map aggregate

site = {
"name":"cai","url":"123"}
print(" The websites :{name}, Address {url}".format(**site))

5. Use the index of the list to set parameters

list = ["IT Private school ","www.t"]
str = " Website name :{0[0]}, website :{0[1]}, Time :{1}".format(list,2020)
print(str)

6.f-strings

name = " Zhang San "
age = 18
print(f" Hello ,{
name} This year, {
age} Year old ")

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved