Python基礎文法

來源:互聯網
上載者:User

標籤:報錯   處理   第一個字元   name   nbsp   python   values   class   字典   

# -*- coding:utf8 -*-print "hello python"if True:    print "True"else:    print"False"x = "a"y = "b"# 換行輸出# 中文注釋報錯,需要加入  # -*- coding:utf8 -*-print xprint y# 不換行輸出輸出print x,print y,counter = 100  # 賦值整形變數miles = 100.0  # 浮點型name = "John"  # 字元型print counterprint milesprint  namea = b = c = 1print a, b, cprint aprint bprint ca, b, c = 1, 2, "john"print a, b, cvar1 = 1var2 = 10print"var1的值是", var1del var1print "處理後var1的值是空"str = ‘Hello World!‘print str  # 輸出完整字串print str[0]  # 輸出字串中的第一個字元print str[2:5]  # 輸出字串中第三個至第五個之間的字串print str[2:]  # 輸出從第三個字元開始的字串print str * 2  # 輸出字串兩次print str + "TEST"  # 輸出串連的字串print "================="list = [‘runoob‘, 786, 2.23, ‘john‘, 70.2]tinylist = [123, ‘john‘]print list  # 輸出完整列表print list[0]  # 輸出資料行表的第一個元素print list[1:3]  # 輸出第二個至第三個的元素print list[2:]  # 輸出從第三個開始至列表末尾的所有元素print tinylist * 2  # 輸出資料行表兩次print list + tinylist  # 列印組合的列表print "======================="tuple = (‘runoob‘, 786, 2.23, ‘john‘, 70.2)tinytuple = (123, ‘john‘)print tuple  # 輸出完整元組print tuple[0]  # 輸出元組的第一個元素print tuple[1:3]  # 輸出第二個至第三個的元素print tuple[2:]  # 輸出從第三個開始至列表末尾的所有元素print tinytuple * 2  # 輸出元組兩次print tuple + tinytuple  # 列印組合的元組tuple = ( ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 )list = [ ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 ]# tuple[2] = 1000   元組中是非法應用list[2] = 1000     # 列表中是合法應用print list[2]print "======================"dict = {}dict[‘one‘] = "This is one"dict[2] = "This is two"tinydict = {‘name‘: ‘john‘, ‘code‘: 6734, ‘dept‘: ‘sales‘}print dict[‘one‘]  # 輸出鍵為‘one‘ 的值print dict[2]  # 輸出鍵為 2 的值print tinydict  # 輸出完整的字典print tinydict.keys()  # 輸出所有鍵print tinydict.values()  # 輸出所有值

 

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.