python筆錄第一周

來源:互聯網
上載者:User

標籤:--   think   賦值   對不起   loop   方式   format   while迴圈   次數   

賦值列印

name = "您好,世界"
msg = "i‘m alex li"

print(name)
print(msg)

#單行注釋
"""
多行注釋
"""

---------------------------------------------------------------------

三種輸出方式:
一:
拼接方式,不推薦使用,每次都要開闢新記憶體

二:
info2 = ‘‘‘
---- info of {_name}----
name:{_name}
age:{_age}
job:{_job}
salary:{_salary}
‘‘‘.format(_name = name,
_age = age,
_job = job,
_salary = salary)
print(info2)
三:
info3 = ‘‘‘
---- info of {0} ----
name:{0}
age:{1}
job:{2}
salary:{3}
‘‘‘.format(name, age, job, salary)
print(info3)

---------------------------------------------------------------------

條件判斷:

import getpass
#密文匯入架構(終端顯示)

#存密碼
_username = ‘zhou‘
_password = ‘abc123‘
username = input("username:")
#password = getpass.getpass("password:")
password = input("password:")


#if else邏輯
#else強制縮排
if _username == username and _password == password:
#if的子代碼
print("welcome to user {name} python".format(name=username))
else:
#else的子代碼
print("Invalid username or password!")

print("我的Tina")
---------------------------------------------------------------------
while迴圈:
count = 0
while True:
print("count:", count)
count = count + 1 #count += 1

if count == 10 :
break

---------------------------------------------------------------------
三次輸入練習:
age_of_oldboy = 56;

count = 0
while count < 3:

guess_age = int(input("guess age:"))

if guess_age == age_of_oldboy :
print("YES,you got it")
elif guess_age > age_of_oldboy :
print("think smaller...")
else:
print("think bigger...")
count += 1
print("count:", count)

else:
print("對不起,您的次數已經使用完了")
---------------------------------------------------------------------
for迴圈列印:
#迴圈10次  range相當於變數的集合,一組資料 0-9

#列印0,2,4,6,8 0,10,2
#列印1,3,5,7,9 1,10,2
for i in range(0, 10, 3) :
print("loop", i)
for i in range(10) :
print("loop", i)

for迴圈的嵌套:
for i in range(4) :
print("-------", i)
for j in range(4) :
print(j)
if j > 1 :
break
---------------------------------------------------------------------






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.