zoukankan      html  css  js  c++  java
  • 1-python入门1

    内存管理: 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 = 1
    print('Now, Print the numbers: ', end=' ')
    while x < 11:
        print(x, end=' ')
        if x == 6:
            x += 2
            print("  ", end='')
        else:
            x += 1
    

    方法二

    print('
    ')
    x = 0
    while x < 10:
        x += 1
        if x == 7:
            continue
        print(x, end=' ')
    

    求1-100的和

    print('
    ')
    y = 1
    sum = 0
    while y < 101:
        sum += y
        y += 1
    print('1-100的所有数的和是:', sum)
    
    print('
    ')
    

    求 1-100内所有的偶数

    print('100以内所有的偶数: ', end='')
    for i in range(1, 101):
        if i % 2 == 0:
            print(i, end=' ')
    

    求100以内的奇数

    print('
    ')
    print('100以内所有的奇数: ', end=' ')
    for ii in range(1, 101):
        if ii % 2 != 0:
            print(ii, end=' ')
    
    print('
    ')
    

    求1-2+3-4+5 ... 99的所有数的和

    sum = 0
    for 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的所有数的和是: 5050
    
    
    100以内所有的偶数: 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= 50
    Please Input Your Name: cx2c
    Please Input Your Password: cc
    False
    Please Input Your Name: cx2c
    Please Input Your Password: cx2c
    Login in successful
    
  • 相关阅读:
    Git的简单使用
    git中查看全部分支的命令
    ModuleNotFoundError: No module named '__main__.base'; '__main__' is not a package(即 if __name__=='__main__'的深入理解)
    django中使用filter()(即对QuerySet操作)时踩的坑
    django模型中如何创建数据并保存到数据库
    django中使用mysql创建索引时报错MySQL does not support a database index on longtext columns
    python环境的编码
    synchronized关键字以及实例锁 类锁
    深拷贝与浅拷贝
    java String不可变对象,但StringBuffer是可变对象
  • 原文地址:https://www.cnblogs.com/cx2c/p/7050067.html
Copyright © 2011-2022 走看看