Python小知識點

2022-05-05 16:00:09 字數 844 閱讀 2885

#

!/usr/bin/env python

#-*- coding:utf-8 -*-

import

syschoice = input("

是否退出?")

if choice == 'y'

or choice == 'y'

: exit(

'成功退出了

')#這裡面還可以輸出內容,很好玩

#

!/usr/bin/env python

#-*- coding:utf-8 -*-

import

sys,time

for i in range(100):

sys.stdout.write('#

') #

python列印進度條,python2.7可用

time.sleep(0.3)

#

!/usr/bin/env python

#-*- coding:utf-8 -*-

import

sys,time

'''python列印進度條,比較美觀

'''for i in range(31):

sys.stdout.write('\r

')  #每一次清空原行

sys.stdout.write(

'%s%% |%s

' %((int(i/30*100), int(i/30*100)*'*'

))) sys.stdout.flush()  #強制重新整理到螢幕

time.sleep(0.3)

Python小知識點

1.時間戳 從1970年到現在的秒數 time2 time.time print time2 date9 datetime.datetime.now print date9.timestamp 上面是兩種用到時間戳的 stamp 郵戳。timestamp 時間戳,時間線。2.執行緒休眠 爬蟲 獲取對...

Python小知識點

1.預設引數 必須放在引數列表的隊尾 普通形參必須放在預設引數的前面 def test a,b 3 passtest test 2.函式引數可以為任意型別 testb testa 3.args返回的是乙個元組 4.map函式裡面需要兩個值 值1 必須是函式 值2 序列 容器 作用 將序列裡面的每個元...

python 小知識點

python strip 方法用於移除字串頭尾指定的字元 預設為空格或換行符 或字串行。注意 該方法只能刪除開頭或是結尾的字元,不能刪除中間部分的字元。strip 方法語法 str.strip chars 返回移除字串頭尾指定的字元生成的新字串。以下例項展示了strip 函式的使用方法 以上例項輸出...