python之再學習----簡單的for的練習

來源:互聯網
上載者:User

標籤:names   file   oda   date   div   else   log   end   learn   

# filename:python2.24(2).py
# author:super
# date:2018-2-24

# 使用for列印出一個List
print(‘today to learn the ‘)
names = [‘aa‘, ‘bb‘, ‘cc‘]
for i in names:
print(i)

# 使用range來產生1,2,3,4,5
for value in range(1, 5):
print(value)

# 使用range來產生1-15的奇數
number = list(range(1, 15, 2))
print(number)

# 使用range來產生1-10的平方數
squares = []
for i in range(1,11):
squares.append(i**2)
print(squares)

# 使用range來產生1-10的平方數

squares2 = [i**2 for i in range(1, 11)]
print(squares2)

# practice

for i in range(1,21):
print(i)

list2 = list(range(1, 21, 2))
for i in list2:
print(i)

# 產生1-30中可以除以3的整數
list3= list(range(1, 31))
b = []
for i in list3:
if(i%3==0):
b.append(i)
else:
continue
print(b)
# 使用range來產生1-10的立方數
list4 = [i**3 for i in range(1,11)]
print(list4)

python之再學習----簡單的for的練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.