初學之python基礎

什麼是python?

  Python (英國發音:/ˈpaɪθən/ 美國發音:/ˈpaɪθɑːn/), 是一種面向對象的解釋型計算機程序設計語言,由荷蘭人Guido van Rossum於1989年發明,第一個公開發行版發行於1991年。python能夠應用於衆多領域,如:數據分析、組件集成、網絡服務、圖像處理、數值計算和科學計算等衆多領域,目前主要應用的領域有:雲計算,web開發,科學計算、人工智能,系統運維,金融等方面。在一些公司的應用:谷歌,豆瓣、知乎、春雨醫生、NASA(美國航天局大量使用Python進行數據分析和運算)、Yahoo、Youtube、Dropbox、BT、Facebook等html

 

1、變量

1.變量名的規則:python

  1.變量不能以數字開頭web

  2.變量能夠是數字,字母,下劃線的組合網絡

  3.關鍵字不能爲變量名運維

2.變量的賦值:ide

    name = "Tom"ui

給變量賦值至關於開闢了一塊內存,變量名至關於門牌號,值至關於門。雲計算

2、輸入

 1 username = input('請輸入用戶名:') 2 password = input("請輸入密碼:") 人工智能

3、條件語句

 1   username = input('請輸入用戶名:')
 2   password = input("請輸入密碼:")
 3   if username == 'alex' and password == '123':
 4       print("登陸成功")
 5       break
 6   elif username == 'alex' and password != '123':
 7       print('密碼錯誤')
 8   elif username != 'alex' and password == '123':
 9       print("登陸名錯誤")
10   else:
11       print("都出現錯誤")
12   count = count +1

4、While循環

 1 count =0
 2 while count<3:
 3     username = input('請輸入用戶名:')
 4     password = input("請輸入密碼:")
 5 
 6     if username == 'alex' and password == '123':
 7         print("登陸成功")
 8         break
 9     elif username == 'alex' and password != '123':
10         print('密碼錯誤')
11     elif username != 'alex' and password == '123':
12         print('登陸名錯誤')
13     else:
14         print("都出現錯誤")
15     count = count +1
16     if count == 3:
17         print("sorry,已到次數")
用戶登陸

5、continue和break

1 while count>3:
2     if count==2:
3         break
4     else:
5         continue
6         print("不打印本行")
7 print(count)

break是退出本循環spa

continue是退出這次循環,開始下一次循環

6、註釋

  單行註釋:# 被註釋內容

  多行註釋:""" 被註釋內容 """

相關文章
相關標籤/搜索