1-python入門1

來源:互聯網
上載者:User

標籤:weight   apt   video   span   figure   lib   amp   mon   管理   

 

記憶體管理: python 變數重新賦值之後,對應的記憶體位址會變

引用計數

del是解除綁定

記憶體位址複用

>>> x=1>>> id(x)9310240>>> x=2>>> id(x)9310272>>> y=1>>> id(y)9310240

字串格式化控制符

print(‘使用者名稱是: %s 密碼是: %s‘ %)
使用while迴圈列印1 2 3 4 5 6 8 9 10
x = 1print(‘Now, Print the numbers: ‘, end=‘ ‘)while x < 11:    print(x, end=‘ ‘)    if x == 6:        x += 2        print("  ", end=‘‘)    else:        x += 1
方法二
print(‘\n‘)x = 0while x < 10:    x += 1    if x == 7:        continue    print(x, end=‘ ‘)
求1-100的和
print(‘\n‘)y = 1sum = 0while y < 101:    sum += y    y += 1print(‘1-100的所有數的和是:‘, sum)print(‘\n‘)
求 1-100內所有的偶數
print(‘100以內所有的偶數: ‘, end=‘‘)for i in range(1, 101):    if i % 2 == 0:        print(i, end=‘ ‘)
求100以內的奇數
print(‘\n‘)print(‘100以內所有的奇數: ‘, end=‘ ‘)for ii in range(1, 101):    if ii % 2 != 0:        print(ii, end=‘ ‘)print(‘\n‘)
求1-2+3-4+5 ... 99的所有數的和
sum = 0for i in range(1, 100):    if i % 2 == 0:        sum -= i        print(‘-‘, i, end=‘‘)    else:        sum += i        print(‘+‘, i, end=‘‘)print(‘=‘, sum)
使用者登陸(三次機會重試)
username = (‘cx2c‘)password = (‘cx2c‘)for i in range(1,4):    user=input(‘Please Input Your Name: ‘)    pasw=input(‘Please Input Your Password: ‘)    if username == user and password==pasw:        print(‘Login in successful‘)        break    else:        print(‘The %sth time False,Try Again‘ %i)
列印結果
Now, Print the numbers:  1 2 3 4 5 6   8 9 10 1 2 3 4 5 6 8 9 10 1-100的所有數的和是: 5050100以內所有的偶數: 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 100以內所有的奇數:  1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 + 1- 2+ 3- 4+ 5- 6+ 7- 8+ 9- 10+ 11- 12+ 13- 14+ 15- 16+ 17- 18+ 19- 20+ 21- 22+ 23- 24+ 25- 26+ 27- 28+ 29- 30+ 31- 32+ 33- 34+ 35- 36+ 37- 38+ 39- 40+ 41- 42+ 43- 44+ 45- 46+ 47- 48+ 49- 50+ 51- 52+ 53- 54+ 55- 56+ 57- 58+ 59- 60+ 61- 62+ 63- 64+ 65- 66+ 67- 68+ 69- 70+ 71- 72+ 73- 74+ 75- 76+ 77- 78+ 79- 80+ 81- 82+ 83- 84+ 85- 86+ 87- 88+ 89- 90+ 91- 92+ 93- 94+ 95- 96+ 97- 98+ 99= 50Please Input Your Name: cx2cPlease Input Your Password: ccFalsePlease Input Your Name: cx2cPlease Input Your Password: cx2cLogin in successful

 

1-python入門1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.