• python学习之路---编程风格规范


    1、导入模块:

    import os
    from os import system
    import SocketServer as SS  --别名
    2、使用Tab键:
    [root@cheeron python]# cat tab.py
    #python startup file
    import sys
    import readline
    import rlcompleter
    import os
    #tab completion
    readline.parse_and_bind('tab: complete')
    #history file
    histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
    #try:
    #       readline.read_history_file(histfile)
    #except IOError:
    #       pass
    3、格式化输出:
    #!/usr/bin/env python
    this_year=2015
    name=raw_input('what is your name: ')
    age=int(raw_input('how old are you? '))
    sex=raw_input('how old are you? ')
    dep=raw_input('how old are you? ')
    messages = ''' information of the company staff:
            Name:%s
            Age :%s
            Gender :%s
            Dep :%s
            ''' % (name,age,sex,dep)
    print messages
     
     
    4、标准化输出:
      1 #!/usr/bin/env python
      2 import sys
      3 user = 'cheeron'
      4 times=0
      5 while True:
      6   if times<3:
      7     name = raw_input('what is your name: ').strip()
      8     if len(name) == 0:
      9         print 'name is not empty,please input a name'
     10         continue
     11     elif user == name:
     12         pass
     13     else:
     14         print "%s is not right,please sign in agin!" % name
     15         times+=1
     16         continue
     17     break
     18   else:
     19     sys.exit()
     20 age = int(raw_input('how old are you? '))
     21 sex = raw_input('Please input your gender: ')
     22 dep = raw_input('Please input your job: ')
     23 print "welcome to sign in",name
     
     1 #!/usr/bin/env python
      2 import sys
      3 user = 'cheeron'
      4 times=0
      5 while True:
      6     name = raw_input('what is your name: ').strip()
      7     if len(name) == 0:
      8         print 'name is not empty,please input a name'
      9         continue
     10     for i in range(3):
     11         name = raw_input('what is your name: ').strip()
     12         if user == name:
     13             pass
     14         else:
     15             print "%s is not right,please sign in agin!" % name
     16             continue
     17         break
     18     else:
     19         print "has login 3 times,exit"
     20         sys.exit()
     21     break
     22 age = int(raw_input('how old are you? '))
     23 sex = raw_input('Please input your gender: ')
     24 dep = raw_input('Please input your job: ')
     25 print "welcome to sign in",name
  • 相关阅读:
    一些问题
    为什么Python在列表,元组和字典的末尾允许使用逗号?
    #!/bin/bash
    gitbook 入门教程之小白都能看懂的 Gitbook 插件开发全流程
    go 学习笔记之10 分钟简要理解 go 语言闭包技术
    gitbook 入门教程之还在搞公众号互推涨粉?gitbook 集成导流工具,轻轻松松躺增粉丝!
    go 学习笔记之仅仅需要一个示例就能讲清楚什么闭包
    go 学习笔记之学习函数式编程前不要忘了函数基础
    go 学习笔记之无心插柳柳成荫的接口和无为而治的空接口
    go 学习笔记之万万没想到宠物店竟然催生出面向接口编程?
  • 原文地址:https://www.cnblogs.com/cheerong/p/4248943.html
Copyright © 2020-2023  润新知