zoukankan      html  css  js  c++  java
  • 9.12 926节

    1.反斜杠以及转义字符的用法  多上网查资料

    2.输入

    print "how old are you?"
    age = raw_input()
    
    age = raw_input("how old are you?")
    

     结果:

    how old are you?

    _                                                  (输入)

    how old are you?_                          (输入)

    print "how old are you?"
    raw_input(">>")
    

    结果:

    how old are you?

    >>_ 

    3.参数,解包,变量

    from sys import argv
    
    a,b,c = argv
    
    print a,b,c
    

     结果(文件名为a.py 后面参数为 1,2)

    a.py 1 2

    注意参数变量个数要和解包数量想对应

    4.文件处理

    from sys import argv
    
    file1,file2 = argv
    
    print "opening the file "
    
    a = open (file2,"w")
    
    print "truncating the file "
    
    a.truncate()
    
    print "two lines:"
    a.write("abcdef")
    a.write("\n")
    a.write('ghijk')
    a.write(\n)
    

     结果:

    opening the file

    truncating the file

    two lines:

    abcdef

    ghijk

    还有更多的文件操作 各种命令

    多看资料

    5.函数

    def print_two(*args):
        arg1,arg2 = args
        print "arg1: %r,arg2: %r")%(arg1,arg2)
    
    def print_one(arg1):
        print "arg1: %r"%arg1
    
    print_two("fan","year")
    print_one("cool")
    

     结果:

    'fan''year'

    'cool'

    def add(a,b):
        return a-b
    
    print add(6,2)
    

     结果:
    4

    注意函数有严格的缩进要求

  • 相关阅读:
    [12.19模拟赛]矩形|扫描线+set
    网 络
    数组(二维)
    数组
    02-线程的三种创建方式
    01-线程(概念篇)
    IO流-文件操作
    Serializable 可串行化接口
    PrintStream 类
    ObjectIntputStream / ObjectOutputStream 类
  • 原文地址:https://www.cnblogs.com/fanyear/p/4803111.html
Copyright © 2011-2022 走看看