Python3基礎篇--print的使用

Xlucas發表於2017-11-21

在Python2中有互動函式raw_input()和input()但是在Python3中不存在raw_input()函式,只有input()函式,下面我們介紹print做格式化的列印

程式碼

name=input('input you name')
age=input('input you age')
job=input('input you job')
salary=input('input you salary')

print('''
the person information %s
        name:%s
        age :%s
        job :%s
      salary:%s
''' % (name,name,age,job,salary))

結果

input you namexlucas
input you age22
input you jobIT
input you salary8000

the person information xlucas
        name:xlucas
        age :22
        job :IT
      salary:8000

print(‘中午’,end=”) 去掉回車換行符

格式的型別有:
d,i 帶符號的十進位制整數
o 不帶符號的八進位制
u 不帶符號的十進位制
x 不帶符號的十六進位制(小寫)
X 不帶符號的十六進位制(大寫)
e 科學計數法表示的浮點數(小寫)
E 科學計數法表示的浮點數(大寫)
f,F 十進位制浮點數
g 如果指數大於-4或者小於精度值則和e相同,其他情況和f相同
G 如果指數大於-4或者小於精度值則和E相同,其他情況和F相同
C 單字元(接受整數或者單字元字串)
r 字串(使用repr轉換任意python物件)
s 字串(使用str轉換任意python物件)

部分函式:
abs(number),返回數字的絕對值
cmath.sqrt(number),返回平方根,也可以應用於負數
float(object),把字串和數字轉換為浮點數
help(),提供互動式幫助
input(prompt),獲取使用者輸入
int(object),把字串和數字轉換為整數
math.ceil(number),返回數的上入整數,返回值的型別為浮點數
math.floor(number),返回數的下舍整數,返回值的型別為浮點數
math.sqrt(number),返回平方根不適用於負數
pow(x,y[.z]),返回X的y次冪(有z則對z取模)
repr(object),返回值的字串標示形式
round(number[.ndigits]),根據給定的精度對數字進行四捨五入
str(object),把值轉換為字串

相關文章