python第一天學習內容

來源:互聯網
上載者:User

標籤:方法表   python   and   gpo   自動   使用者   bsp   賦值   比較   

linux下運行python
#頭部加python安裝路徑#!usr/bin/env python
 函數:
print() #輸出input() #輸入
 運算子:
#1.算數運算:+ #加法- #減法* #乘法/ #除法// #取整數 - 返回商的整數部分% #模數 - 返回除法的餘數** #冪 - 返回x的y次冪 #2.比較運算(返回的值是布爾值):== #等於 != #不等於< #小於符號> #大於符號<= #小於等於符號>= #大於等於符號#3.賦值運算:= #賦值+= #加法賦值運算-= #減法賦值運算*= #乘法賦值運算/= #除法賦值運算%= #模數賦值運算**= #冪賦值運算//= #取整數賦值運算#4.邏輯運算子:and #如果兩個結果都同時為真,則返回(true)否則返回(false)or #如果兩個結果有一個為真,返回(true)not #如果結果為真,返回(false)為假,返回(true)#5.成員運算子:in #在指定序列中能找到值返回(true)not in #在指定序列中找不到內容返回(true)

 

變數命名規則:
#只能用數字 字母 底線 並且不能以數字開頭。name = "碼農也瘋狂"name1 = "碼農也瘋狂"_name = "碼農也瘋狂"
字串:
1 # 字串只能用這3種方法表示2 ‘這是一個字串‘3 "這是一個字串"4 """這是一個字串"""
if 判斷語句的使用:
if 1 == 1:    #判斷1是否等於1    print("符合判斷條件,輸出的內容.")else:    print("不符合判斷條件,輸出的內容。")
while 迴圈語句的使用
#死迴圈while 1 == 1:     print("這是一個死迴圈")#輸出1-100的數字n = 1while n < 101:    print(n)    n += 1 
練習題:
# 請輸出1-100以內的奇數n = 1while n < 100:    if n % 2 == 0:        pass    else:        print(n)    n += 1

 

# 請輸出1-100以內的偶數n = 1while n < 100:    if n % 2 == 0:        print(n)    else:        pass    n += 1

 

# 請輸出1-100以內的和n = 1s = 0while n < 101:    s = s + n #儲存n上次相加的和    n += 1 print(s)

 

# 請輸出1,2,3,6,8,10以內的和n = 1while n < 11:    if n == 5 or n == 7 or n == 9: #如果有一個條件符合就直接跳過        pass    else:        print(n)    n += 1

 

# 使用者密碼輸入錯誤3次自動結束程式user_name = "123456" #帳號user_passwd = "123456" #密碼n = 1while n < 4:    if user_name == input("請輸入帳號:") and user_passwd == input("請輸入密碼"): #判斷帳號密碼是否符合        print("登陸成功")        n = 4    else:        print("登陸失敗", n, "次數")    n += 1

 

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.