循序漸進-python-02

來源:互聯網
上載者:User

標籤:available   internet   programs   welcome   keyword   

關鍵字和標識符

下列的標識符是 Python3 的關鍵字,並且不能用於通常的標識符。關鍵字必須完全按照下面拼字:

>>> help()Welcome to Python 3.5‘s help utility!If this is your first time using Python, you should definitely check outthe tutorial on the Internet at http://docs.python.org/3.5/tutorial/.Enter the name of any module, keyword, or topic to get help on writingPython programs and using Python modules.  To quit this help utility andreturn to the interpreter, just type "quit".To get a list of available modules, keywords, symbols, or topics, type"modules", "keywords", "symbols", or "topics".  Each module also comeswith a one-line summary of what it does; to list the modules whose nameor summary contain a given string such as "spam", type "modules spam".help> keywordsHere is a list of the Python keywords.  Enter any keyword to get more help.False               def                 if                  raiseNone                del                 import              returnTrue                elif                in                  tryand                 else                is                  whileas                  except              lambda              withassert              finally             nonlocal            yieldbreak               for                 not                 class               from                or                  continue            global              pass


Python 中 我們不需要為變數指定資料類型。所以你可以直接寫出 num1 = 1 ,這樣變數 abc 就是整數類型。如果你寫出 num2= 1.0 ,那麼變數 abc 就是浮點類型。

>>> num1=1>>> num2=1.0>>> name="wuxinglai">>> print(type(num1))<class ‘int‘>>>> print(type(numnum1  num2  >>> print(type(numnum1  num2  >>> print(type(num2))<class ‘float‘>>>> print(type(name))<class ‘str‘>>>>


通過上面的例子你應該理解了如何在 Python 中定義變數,也就是只需要輸入變數名和值就行了。Python 也能操作字串,它們用單引號或雙引號括起來。


從鍵盤讀取輸入
[email protected]:~/file/1# vim input_age.py
#!/usr/bin/python3#coding:utf8number=int(input("Please Input your age:"))if number >= 18:        print ("你已經是成年人 Your  age is %s and You are already an adult" %number)else:        print ("你是未成年 Your age is %s You are a minor" %number)
[email protected]:~/file/1# python3 input_age.py 
Please Input your age:18
你已經是成年人 Your  age is 18 and You are already an adult
[email protected]:~/file/1# python3 input_age.py
Please Input your age:12
你是未成年 Your age is 12 You are a minor






















本文出自 “有志者,事竟成” 部落格,謝絕轉載!

循序漸進-python-02

聯繫我們

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