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

來源:互聯網
上載者:User

標籤:姓名   輸出   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基本輸出語句/輸入語句/變數解析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.