博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python基础-Alex
阅读量:4556 次
发布时间:2019-06-08

本文共 1212 字,大约阅读时间需要 4 分钟。

格式化字符串:

 
  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次")

 

转载于:https://www.cnblogs.com/fftan/p/5732504.html

你可能感兴趣的文章
out传值
查看>>
CentOS6.8【环境配置篇】
查看>>
线程同步的方式
查看>>
Mongodb 安装
查看>>
WPF窗口贴边隐藏(类似QQ)
查看>>
VS2008无法切换到视图设计器
查看>>
爱情故事:追忆似水流年 回味永恒的爱恋
查看>>
android mvn android:deploy签名问题
查看>>
transient
查看>>
[HDU 4348]To the moon
查看>>
初识【Windows API】--文本去重
查看>>
[转]IOS多线程
查看>>
详解spl_autoload_register() 与 __autoload
查看>>
Axure RP Extension for Chrome安装
查看>>
day_10
查看>>
ArcGIS API for JavaScript 入门教程[6] 再讲数据——Map类之可操作图层
查看>>
tfs2012 的体验地址
查看>>
打造专业外观-九宫图
查看>>
让discuz论坛单独版块贴子侧边栏(用户信息栏)关闭的修改办法
查看>>
倒计时
查看>>