日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python语句分类_Python新手入门【语句类型】

發(fā)布時間:2024/9/3 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python语句分类_Python新手入门【语句类型】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.條件語句if用法

#!/usr/bin/python

# -*- coding: UTF-8 -*-

# 例1:if 基本用法

flag = False

name = 'luren'

if name == 'python': # 判斷變量是否為 python

flag = True # 條件成立時設(shè)置標(biāo)志為真

print 'welcome boss' # 并輸出歡迎信息

else:

print name # 條件不成立時輸出變量名稱

輸出結(jié)果為:

luren # 輸出結(jié)果elif用法

#!/usr/bin/python

# -*- coding: UTF-8 -*-

# 例2:elif用法

num = 5

if num == 3: # 判斷num的值

print 'boss'

elif num == 2:

print 'user'

elif num == 1:

print 'worker'

elif num < 0: # 值小于零時輸出

print 'error'

else:

print 'roadman' # 條件均不成立時輸出

輸出結(jié)果為:

roadman # 輸出結(jié)果

2.循環(huán)語句

2.1 循環(huán)類型while循環(huán)

#!/usr/bin/python

count = 0

while (count < 9):

print('The count is:', count)

count = count + 1

print("Good bye!")

輸出結(jié)果為:

The count is: 0

The count is: 1

The count is: 2

The count is: 3

The count is: 4

The count is: 5

The count is: 6

The count is: 7

The count is: 8

Good bye!for循環(huán)

#!/usr/bin/python

# -*- coding: UTF-8 -*-

for letter in 'Python': # 第一個實例

print '當(dāng)前字母 :', letter

fruits = ['banana', 'apple', 'mango']

for fruit in fruits: # 第二個實例

print '當(dāng)前水果 :', fruit

print "Good bye!"

輸出結(jié)果為:

當(dāng)前字母 : P

當(dāng)前字母 : y

當(dāng)前字母 : t

當(dāng)前字母 : h

當(dāng)前字母 : o

當(dāng)前字母 : n

當(dāng)前水果 : banana

當(dāng)前水果 : apple

當(dāng)前水果 : mango

Good bye!

總結(jié)

以上是生活随笔為你收集整理的python语句分类_Python新手入门【语句类型】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。