python快捷鍵與命令函數


tab 自動補齊

alt+P 前一個命令

alt +N 下一個命令

 

"""    """   三重引號為注釋(也可以用單引號)

# 改行后面的都為注釋

 

 

查看Python模塊的位置

>>> import sys

>>> sys.path

['E:\\Python34\\Lib\\idlelib', 'C:\\Windows\\system32\\python34.zip', 'E:\\Python34\\DLLs', 'E:\\Python34\\lib', 'E:\\Python34', 'E:\\Python34\\lib\\site-packages']

 

import 模塊

模塊名.函數名(數據)

數據.函數()

 

dir(__builtins__)  查看pyton內置函數

help(input)  看input()用法

 

 

數據的添加和刪除

>>> movies=["The holy grail","the life of brian","the meaning of life"]

append(),pop()用於增加或者刪除末尾的數據

extend()用於在列表后面加一個數據項集合

remove()刪除一個特定的數據項

insert()在某個具體的位置加上數據

>>> movies.append("wo de ")

>>> print(movies)

['The holy grail', 'the life of brian', 'the meaning of life', 'wo de ']

>>> movies.pop()

'wo de '

>>> print(movies)

['The holy grail', 'the life of brian', 'the meaning of life']

>>> movies.extend(["gillima","chapam"])

>>> print(movies)

['The holy grail', 'the life of brian', 'the meaning of life', 'gillima', 'chapam']

>>> movies.remove("chapam")

>>> print(movies)

['The holy grail', 'the life of brian', 'the meaning of life', 'gillima']

>>> movies.insert(0,"1")

>>> print(movies)

['1', 'The holy grail', 'the life of brian', 'the meaning of life', 'gillima']

 

len處理列表時候表示列表元素的個數,處理元素的時候表示元素的字符個數。

 

>>> for num in range(4):

         print(num)

 

0

1

2

3

#這個里面是不好4的。

 

(role, line_spoken) = each_line.split(':', 1)

 

line_spoken = line_spoken.strip()

#strip(去掉開頭和結尾處的空白符,\n,\r, \t)

 

  (mins, secs) = time_string.split(splitter)

   return(mins + '.' + secs)

#注意上面的+用來連接兩部分

 

if '-' in time_string:

        splitter = '-'

#注意in的作用

 

set()  #工廠函數,用於去掉重復的部分,沒有重復的數據叫集合。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM