zoukankan      html  css  js  c++  java
  • python1

    1.数据类型

    list 列表[1,2,3]
    tuple 元组(1,2,3)
    dict 字典{"key1":"value1", "key2":"value2"}

    2.字符串类型转换

    a = "哈哈".decode("utf-8")

    3.字符串拼接,%s 字符串的占位符,%d 数值的占位符

    a = "my name is %s dulianyong" % "world's"

    print a 输入结果my name is world's dulianyong

    a = "this is {} {}".format("my", "borther")

    a = "this is {0} {1}".format("my", "apple")

    a = "this is {ss} {kk}".format(ss = "my", kk"apple" = "apple")

    a = "this is %(w)s %(t)s" % {"w":"my", "t":"apple"}

    4.字符串拼接join

    a = "a"
    b = "sssssssssss"
    c = "151sfsdfsdf"
    "".join([a,b,c])
    'asssssssssss151sfsdfsdf'
    ",".join([a,b,c])
    'a,sssssssssss,151sfsdfsdf'

    5.读写文件

    w:write;r:read;a:append

    写:

    d = open("a.txt", "w")

    d.write("hi. second hi.")

    d.close()

    读:

    d = open("a.txt", "r")

    d.readline()//读取一行

    d.read(10)//读取十行

    d.seek(0)//游标回到第一行

    import linecache 使用linecache读取文件,返回的是元组

    print linecache.getline("a.txt", 1)

    print linecache.getlines("a.txt")

  • 相关阅读:
    python:xlrd模块
    psql:转:会引起全表扫描的10种sql语句
    Linux相关
    面试题
    Siege Web服务器性能压力测试工具
    Nginx+uWSGI+Supervisor配置
    SQLAlchemy
    Virtualenv创建虚拟环境
    算法
    Mac常用快捷键
  • 原文地址:https://www.cnblogs.com/dulianyong/p/10027736.html
Copyright © 2011-2022 走看看