最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網 會員登陸 & 注冊

python3.8 五分鐘就可以入門

2020-05-26 19:38 作者:嗨大成  | 我要投稿

嗨大成帶你五分鐘入門 python編程語言

了解Python的語法(第一個hello world)

print('Hello world!') #打印Hello world

字符串格式

name = '嗨大成'

print('Hello, %s' % name)? # Hello,嗨大成

print('Hello, {}'.format(name))? # string formatting? #也是上面的 Hello,嗨大成

定義函數

def add_one(x):

? ? return x + 1

測試

x = 1

y = 2

print( 'x is equal to y: %s' % (x == y))

z = 1

print ('x is equal to z: %s' % (x == z))

names = ['Donald', 'Jake', 'Phil']

words = ['Random', 'Words', 'Dogs']

if names == words:

? ? print ('Names list is equal to words')

else:

? ? print ("Names list isn't equal to words")

new_names = ['Donald', 'Jake', 'Phil']

print ('New names list is equal to names: %s' % (new_names == names))

定義類里面的2個函數

class Talker(object):

? ? def greet(self, name):

? ? ? ? print ('Hello, %s!' % name)

? ? def farewell(self, name):

? ? ? ? print ('Farewell, %s!' % name)

定義list

dynamic_languages = ['Python', 'Ruby', 'Groovy']

dynamic_languages.append('Lisp')

定義字典

numbered_words = dict()

numbered_words[2] = 'world'

numbered_words[1] = 'Hello'

numbered_words[3] = '!'

循環(huán)

while True:?

? ? if value == wanted_value: #判斷條件

? ? ? ? break

? ? else:

? ? ? ? pass

定義多行字符串

string = '''This is a string with embedded newlines.

Also known as a tripled-quoted string.

? ? Whitespace at the beginning of lines is included,

so the above line is indented but the others are not.

'''

源代碼上拆分長字符串

string = ('This is a single long, long string'

? ? ? ? ? ' written over many lines for convenience'

? ? ? ? ? ' using implicit concatenation to join each'

? ? ? ? ? ' piece into a single string without extra'

? ? ? ? ? ' newlines (unless you add them yourself).')

循環(huán)

for x in xrange(1, 4):

? ? print ('Hello, new Python user!'

? ? ? ? ? ?'This is time number %d') % x

列表

l = [x**2 for x in range(4)]

print(l)

# [0, 1, 4, 9]

有條件的

squares = {x**2 for x in [0,2,4] if x < 4}

print(squares)

# {0, 4}



python3.8 五分鐘就可以入門的評論 (共 條)

分享到微博請遵守國家法律
神农架林区| 卫辉市| 隆回县| 青铜峡市| 故城县| 莆田市| 龙口市| 兴文县| 金秀| 西充县| 长葛市| 浦城县| 吉首市| 全州县| 长垣县| 蛟河市| 锦州市| 武威市| 卫辉市| 蒲城县| 进贤县| 天水市| 宜宾市| 久治县| 荣成市| 高平市| 垫江县| 井陉县| 沅陵县| 右玉县| 东源县| 嘉善县| 隆尧县| 大同市| 木里| 济源市| 视频| 浮梁县| 嵊州市| 湟源县| 隆子县|