• Python基础-Alex


    格式化字符串

    1. name=input("input your name:")
    2. age=int(input("input your age:"))
    3. job=input("input your job:")
    4. msg='''
    5. information of user %s:
    6. ============================
    7. Name: %s
    8. Age: %d
    9. Job: %s
    10. -----------End--------------
    11. '''%(name,name,age,job)
    12. print(msg)

    Tab补全:

    1. #!/usr/bin/env python
    2. # python startup file
    3. import sys
    4. import readline
    5. import rlcompleter
    6. import atexit
    7. import os
    8. # tab completion
    9. readline.parse_and_bind('tab: complete')
    10. # history file
    11. histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
    12. try:
    13. readline.read_history_file(histfile)
    14. except IOError:
    15. pass
    16. atexit.register(readline.write_history_file, histfile)
    17. del os, histfile, readline, rlcompleter


    if...else语句 验证用户登录:

    1. #!/usr/bin/python
    2. #-*-coding:utf-8 -*-
    3. age=25
    4. counter=0
    5. for i in range(10):
    6. if counter<3:
    7. guess_num=int(input("Input an num:"))
    8. if guess_num==age:
    9. print("you are right")
    10. break
    11. elif guess_num>age:
    12. print("it is > age")
    13. else:
    14. print("it is < age")
    15. else:
    16. #print("你已经输错了3次")
    17. #break
    18. continue_confirm=input("you are attempt three times,Are you continue")
    19. if continue_confirm=='y':
    20. counter=0
    21. continue # 跳出当次循环进入下一个循环
    22. else:
    23. print("bye")
    24. break
    25. counter=counter+1
    26. if i>10:
    27. print("你已经超过10次")













  • 相关阅读:
    EnumMap实现类
    java enum
    openssl生成RSA公钥和私钥对
    rsa 公钥 私钥
    eclispe 通过git向码云上传
    eclipse git 报 git: 401 Unauthorized
    HttpClient 超时时间
    HttpClient 4 和 HttpClient 3 超时
    Java RSA 生成公钥 私钥
    万能适配器
  • 原文地址:https://www.cnblogs.com/fftan/p/5732504.html
Copyright © 2020-2023  润新知