Python基本輸出語句/輸入語句/變量解析


print格式化輸出

# -*- coding: utf-8 -*-
# print (format(val, 'm,n'))
# val:值 format_modifier:輸出占位m,精度n
print (format(12.3456,'6.2f' ))
 12.35
print (format(12.3456,'6.3f' ))
12.346
print (format(12.3456,'6.6f' ))
12.345600
print (format(12.3456,'6.0f' ))
    12

 print輸入語句

input接收的值會轉化為字符型,int()可將值轉化為整型數據,float()將值轉化為浮點型數據

# -*- coding: utf-8 -*-

name = raw_input('請輸入姓名: ')
print name
print type(name)

age = raw_input('請輸入年齡: ')
age = int(age)
print type(age)
age = age + 1
print age

weight = float(raw_input('請輸入體重: '))
print weight
print type(weight)

"""運行結果"""
請輸入姓名: lee
lee
<type 'str'>
請輸入年齡: 13
<type 'int'>
14
請輸入體重: 40.22
40.22
<type 'float'>

變量解析

變量改變只改變指向地址不改變指向內容

# -*- coding: utf-8 -*-

x = 13
print x, id(x)
y = 12
print y, id(y)
x = y
print x, id(x)
z = 13
print z, id(z)

"""運行結果"""

13 73496064
12 73496076
12 73496076
13 73496064

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM