python基礎、字串和if條件陳述式

來源:互聯網
上載者:User

標籤:美女   XA   使用者   python基礎   strong   變化   檔案   python2   服務   

一:Python基礎

  1、檔案尾碼名: .py

  2、Python2中讀中文要在檔案頭寫: -*-coding:utf8-*-

  3、input用法      n為變數,代指某一變化的值

    n = input (‘請輸入使用者名稱:‘)     等到使用者輸入值,就會將使用者輸入的值賦值給n,n代指使用者輸入的內容。

  4、變數只能由字母、數字、底線組成。

    不能以數字開頭。

    不能用Python的關鍵字開頭:

  5、n="花椒"      賦值

     n=="花椒"    比較

二:字串

 

       字串:引號引起來的部分叫字串。

       字元:引號引起來的字串內容叫字元。

  字串加法

n1 = "alex"n2 = "sb"n3 = n1 + n2列印n3為:alexsb

  字串乘法:

n1 = "alex"n2 = n1 *10列印n2為:alexalexlaex.....(10個alex)

數字:

  例如:

n1 = 9n2 = 2                            n3 = n1 + n2   n3 = n1 - n2    n3 = n1 * n2n3 = n1 / n2n3 = n1 % n2        除法取餘數n3 = n1 ** n2
n3 = n1 // n2 除法取商

 三:f條件陳述式

if inp == "進階會員"    print("美女")elif inp == "白金會員"    print("大摩")elif inp == "鉑金會員"    print("一線小明星")else:    print("城管")print("開始服務吧")

四:while死迴圈

   

count=0while count < 10 :    print(count)    count = count +1print("1、2、3、、")

 

  

 

python基礎、字串和if條件陳述式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.