2. 鍩虹鏁版嵁绫诲瀷

[TOC]

鏁版嵁绫诲瀷

瀛楃缂栫爜锛�

鎴戜滑閫氬父杩樻槸鐢℅BK鎸囦唬涓枃windows鍐呯爜

usf-8鏄缂栫爜鐨勫帇缂╁拰浼樺寲锛屽湪缂栧啓python鐨勬椂鍊欓渶瑕佸0鏄庣粰python瑙i噴鍣紙璇翠簡python鏄В閲婂瀷璇█锛夛紝浣跨敤浠�涔堢紪鐮佹潵鎵ц婧愪唬鐮侊細

#!/usr/bin/env python
# -*- coding:utf-8 -*-

娉ㄩ噴锛�

鍗曡娉ㄩ噴#
澶氳娉ㄩ噴 ``` ```

鐢ㄦ埛杈撳叆锛�

input()
闇�瑕侀檺鍒惰緭鍏ョ被鍨嬬殑鏃跺�欙紝鍦╥nput澶栭潰濂楁帴涓�涓�鏁版嵁绫诲瀷渚嬪int(input())

杈撳叆瀵嗙爜鏃讹紝濡傛灉鎯宠涓嶅彲瑙侊紝闇�瑕佸埄鐢�getpass妯″潡涓殑getpass鏂规硶锛�

import getpass
pwd = getpass.getpass('enter your pwd:')

鏁版嵁绫诲瀷

鍦ㄨ繖閲岀┛鎻掕В閲婃暟鎹被鍨�

  1. 鏁板瓧
    int鏁村瀷
    long闀挎暣鍨嬶細鍦╬ython2.2浠ュ悗鐨勭増鏈噷锛宲ython鍦ㄩ暱鏁存暟鎹悗闈笉鍔燣涔熶笉浼氭湁澶ぇ鐨勯棶棰�
    float娴偣鍨�
    complex澶嶆暟

  2. 甯冨皵鍊�
    鐪�/鍋�

  3. 瀛楃涓�
    'hello world'

  • 瀛楃涓茬殑鏍煎紡鍖栬緭鍑�
name = 'scott'
print('i am %s'%name)

#瀛楃涓叉槸%s 锛� 鏁存暟%d 锛� 娴偣鏁� %f
  • 瀛楃涓叉搷浣滄柟娉曪細

print(name.strip()) #鑴�

print(name.split()) #鍒嗗壊

print(name.len()) #闀垮害

print(name.index('s')) #绱㈠紩

name1 = 'scott,jack,jerry'

print(name[0:4])
#杈撳嚭缁撴灉涓衡�榮cot鈥�
#璇存槑python鍒囩墖鐨勪竴鏉¤鍒�

#**椤惧ご涓嶉【灏�**
#鑼冧緥锛�
print(name [-6:])
print(name [-6:1])
print(name [0::3])   #闅斿嚑涓瓧绗﹀彇涓�娆�

鍒楄〃鍜屽瓧鍏�

list鍒楄〃

  • 瀹氫箟鍒楄〃
>>> name = ['scott','jack','jerry','peter']
  • 娣诲姞鍏冪礌锛坅ppend锛�
>>> name.append('super')
>>> name
['scott', 'jack', 'jerry', 'peter', 'super']
  • 瀹氫綅娣诲姞鍏冪礌锛坕nsert锛�
>>> name.insert(2,'alex')
>>> name
['scott', 'jack', 'alex', 'jerry', 'peter', 'super']
  • 瀹氫綅鍒犻櫎鍏冪礌
>>> name.pop(3)
'jerry'
>>> name
['scott', 'jack', 'alex', 'peter', 'super']

涓嶆坊鍔犲弬鏁帮紝榛樿鍒犻櫎鏈�鍚庝竴涓�

>>> name.pop()
'super'
  • 鍦ㄥ垪琛ㄤ腑瀹氫綅鍏冪礌浣嶇疆
>>> name.count('jack')
1
list鐨勬繁娴呮嫹璐�
## 璁$畻缁撴灉浠ュ強涓轰粈涔堬紵
a = [1, 2, [3, "hello"], {"egon": "aigan"}]
# 褰㈠弬a鎸囧悜涓�鍧楀偍瀛樺垪琛ㄧ殑鍐呭瓨浣嶇疆
b = a[:]
# 褰㈠弬b鎸囧悜鐩稿悓鐨勪綅缃�

a[0] = 5
# 鍘熸湰a鐨勫垪琛ㄤ慨鏀逛簡鏌愪釜鍊硷紝a鎸囧悜鍒殑鍐呭瓨鍦板潃锛岃鍦板潃瀛樺偍鐫�鏂扮殑鍒楄〃
# a淇敼浜嗘煇涓竴灞傚垪琛ㄥ厓绱犵殑浣嶇疆锛宐涓嶅彈褰卞搷
a[2][0] = 666
# a淇敼浜嗘煇涓簩灞傚垪琛ㄥ厓绱犵殑浣嶇疆锛宐鍙楀埌褰卞搷
print(a)
print(b)
# 鐭ヨ瘑鐐癸細娣辨祬鎷疯礉锛宐 = a[:]璁゜鑾峰緱浜哸鐨勫�硷紝浣嗘槸浜岃�呭苟涓嶅叕鐢ㄤ竴鍧楀唴瀛樺湴鍧�
# 浣嗘槸涓や釜鍒楄〃涓殑浜岀骇鍒楄〃锛屾寚鍚戠殑鏄悓涓�鍧楀唴瀛樺湴鍧�锛�
# 鎵�浠ュ綋涓や釜鍒楄〃涓紝涓�绾у厓绱犲彂鐢熸敼鍙樼殑鏃跺�欙紝浜掍笉褰卞搷锛屼絾褰撲簩绾у厓绱犲彂鐢熸敼鍙樼殑鏃跺�欙紝浜岃�呭悓鏃跺彂鐢熷彉鍖栥��
# 鏈夌敤浜庡己鍒舵繁鎷疯礉鐨勬ā鍧�

dict 瀛楀吀

key Value 閿��
key 蹇呴』鍞竴

  • 瀛楀吀涓轰粈涔堟槸鏃犲簭鐨勶紵
name= {
    9527:{'name':'scott','age':23},
    9528:{'name':'jack','age':24},
    9529:{'name':'jerry','age':22},
    9530:{'name':'peter','age':22}
    }
  • 鍙栧��
    print(name[9527]['age'])

  • 澧�
    name[9526] = 'yage'

  • 鍒�
    print(name.pop(9526)) #---浼氳繑鍥炰粬鐨勫��
    print(name.popitem()) #---闅忔満鍒犻櫎涓�涓�

  • 鏀�

  • 淇敼鏌愪釜瀛楀吀鍏冪礌
    name[9528][0] = 'super jack'

  • 鍦ㄦ煇涓瓧鍏镐腑澧炲姞涓�涓暟瀛�
    name[9529].append(28)

  • 鏌�
print(name.get(9527))
print(9527 in name)
print(name.keys())
print(name.values())
  • loop
  • 鍙墦鍗発ey
    for i in name: print(i)

for i in name.items(): print (i)

for k,v in names.items(): print(k,v)

  • 鏇存柊
dict2 = {
    9523:{'name':'sco','age':23}
    9524:{'name':'jac','age':24}
    9525:{'name':'jer','age':22}
    9536:{'name':'pet','age':22}
    }

.update()
濡傛灉dict.update(dict2)
濡傛灉dict2涓湁dict宸茬粡鏈夌殑閿�硷紝灏�鏇存柊瑕嗙洊璇ラ敭鍊�

你可能感兴趣的:(2. 鍩虹鏁版嵁绫诲瀷)