python的輸入輸出與迴圈

來源:互聯網
上載者:User

標籤:passwd   格式   輸出變數   執行   類型   type   字元   else   字串   

1. python的輸入與輸出

name = input("name:")  輸入name,預設的類型為字串類型

age = int(input("age:"))  強制類型轉化為int類型

print(type(age))     輸出變數的類型

字元拼接輸出:

第一種格式:

info = ‘‘‘

------- info of %s ------

Name:%s

Age:%d

Job:%s

Salary:%s

‘‘‘ % (name, name, age, job, salary)

第二種格式

info = "‘

------info of {_name} ------

Name:{_name}

Age:{_Age}

Job:{_Job}

Salary:{_salary}

‘‘‘.format(_name = name,

    _age = age,

    _job = job,

    _salary = salary)

第三種格式

info = ‘‘‘

------info of {0} ------

Name:{0}

Age:{1}

Job:{2}

Salary:{3}

‘‘‘.format(name, age, job, salary)

2. 登陸時隱藏密碼

import getpass

passwd = getpass.getpass("passwd:")

3. 判斷語句

if guess_age == age_of_oldboy:

  print("yes,you got it")   #縮排和java的括弧作用相同

  break

elif guess_age > age_of_oldboy:

  print("think smaller...")

else:

  print("think bigger...")

4. 迴圈語句

4.1 for 迴圈

for i in range(0,10,2)

  print("loop", i)

else:

  #正常(非break)結束時候執行此處代碼,break結束時不執行此代碼

4.2 while迴圈

while True:#死迴圈

while count < 3:

else:

  #正常結束時執行此處代碼

  

 

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.