python 高階學習之2

2021-06-22 18:51:07 字數 891 閱讀 2667

>>> print ("hello")    

hello

>>> mystring = 'aa'

>>> print(mystring)

aa下劃線(_)在直譯器中有特別的含義,表示最後乙個表示式的值

>>> a="22"

>>> _    

traceback (most recent call last):

file "", line 1, in

nameerror: name '_' is not defined

>>> a

'22'

>>> _

'22'

python 的print 語句,與字串格式運算子( % )結合使用,可實現字串替換功能

>>> print("%s is %d" % ("ss",0))

ss is 0

>>> logfile = open('1.txt', 'a') 

>>> print >> logfile, 'fatal error: invalid input!'

>>> logfile.close()

>>> user = raw_input('enter login name: ')

enter login name: daf

>>> print 'your login is:', user

your login is: daf

#

def foo():

"this is a doc string."

return true

Python高階學習(2)

import random import collections 產生隨機數字的序列 numbers random.randint 1,20 for in range 60 print numbers 給出整個列表中數值的統計資訊 counter collections.counter number...

python 高階學習之4

for item in e mail net surfing homework chat print item e mail net surfing homework chat for item in e mail net surfing homework chat print item e mai...

python 高階學習之10

s s spa oil spa oil s join ss ww 21 s ss ww 21 foo hello world foo helloworld 通過這種方法,你可以把長的字串分成幾部分來寫,而不用加反斜槓 如果把乙個普通字串和乙個unicode 字串做連線處理,python 會在連線操作...