標籤:姓名 輸出 str 解析 print 語句 weight 輸入 oat
print格式化輸出
# -*- coding: utf-8 -*-# print (format(val, ‘m,n‘))# val:值 format_modifier:輸出佔位m,精度nprint (format(12.3456,‘6.2f‘ )) 12.35print (format(12.3456,‘6.3f‘ ))12.346print (format(12.3456,‘6.6f‘ ))12.345600print (format(12.3456,‘6.0f‘ )) 12
print輸入語句
input接收的值會轉化為字元型,int()可將值轉化為整型資料,float()將值轉化為浮點型資料
# -*- coding: utf-8 -*-name = raw_input(‘請輸入姓名: ‘)print nameprint type(name)age = raw_input(‘請輸入年齡: ‘)age = int(age)print type(age)age = age + 1print ageweight = float(raw_input(‘請輸入體重: ‘))print weightprint type(weight)"""運行結果"""請輸入姓名: leelee<type ‘str‘>請輸入年齡: 13<type ‘int‘>14請輸入體重: 40.2240.22<type ‘float‘>
變數解析
變數改變只改變指向地址不改變指向內容
# -*- coding: utf-8 -*-x = 13print x, id(x)y = 12print y, id(y)x = yprint x, id(x)z = 13print z, id(z)"""運行結果"""13 7349606412 7349607612 7349607613 73496064
Python基本輸出語句/輸入語句/變數解析