python·那些不值钱的经验

python·那些不值钱的经验时间:2018-11-22整理:byzqypython读写文本文件1#-*-coding:utf-8-*-23defread_file(file):4withopen(file,'r')asf:5print(f.read())6f.clos

大家好,欢迎来到IT知识分享网。

  • 时间:2018-11-22 整理:byzqy

python读写文本文件

python·那些不值钱的经验
python·那些不值钱的经验

 1 # -*- coding: utf-8 -*-
 2 
 3 def read_file(file):
 4     with open(file, 'r') as f:
 5         print(f.read())
 6     f.close()
 7 
 8 def write_file(file):
 9     with open(file, 'a') as f:
10         for i in range(10):
11             f.write(str(i) + '\n')
12     f.close()
13 
14 file = 'test.txt'
15 write_file(file)
16 read_file(file)

View Code

转自:https://blog.csdn.net/u010429424/article/details/76136727

python字符串拼接

python·那些不值钱的经验
python·那些不值钱的经验

 1 # python中字符串拼接的方法
 2 
 3 # 1. 加号
 4 print 'Python' + 'Tab'
 5 ==>PythonTab
 6 
 7 # 2. 逗号
 8 print 'Python','Tab'
 9 ==>Python Tab
10 
11 # 3. 直接连接
12 print 'Python''Tab'
13 ==>PythonTab
14 print 'Python'   'Tab'
15 ==>PythonTab
16 
17 # 4. 格式化
18 print '%s %s'%('Python', 'Tab')
19 ==>Python Tab
20 
21 # 5. join
22 str_list = ['Python', 'Tab']
23 a = ''
24 print a.join(str_list)
25 ==>PythonTab
26 
27 # 6. 多行字符串拼接()
28 s = ('select *'
29      'from atable'
30      'where id=888')
31 print s, type(s)
32 ==>select *from atablewhere id=888 <type 'str'>
33 
34 # 7. 使用单引号(''' ''')或者双引号(""" """)
35 name = input("Please input your name: ")
36 age = input("Please input your age: ")
37 sex = input("Please input your sex: ")
38 
39 message = '''
40 Information of %s:
41 Name:%s
42 Age:%s
43 Sex:%s
44 '''%(name,name,age,sex)
45 print(message)
46 ==>Information of Alex:
47     Name:Alex
48     Age:38
49     Sex:girl

View Code

源自:python·那些不值钱的经验

源自:python·那些不值钱的经验

python字符串操作之字符串分割

python·那些不值钱的经验
python·那些不值钱的经验

 1 #定义一个字符串str1
 2 >>> str1 = "3w.gorly.test.com.cn"
 3 
 4 #使用默认分隔符分割字符串str1
 5 >>> print str1.split()
 6 ['3w.gorly.test.com.cn']
 7 
 8 #指定分隔符为'.',进行分割字符串str1
 9 >>> print str1.split('.')
10 ['3w', 'gorly', 'test', 'com', 'cn']
11 
12 #指定分隔符为'.',并且指定切割次数为0次
13 >>> print str1.split('.',0)
14 ['3w.gorly.test.com.cn']
15 
16 #指定分隔符为'.',并且指定切割次数为1次
17 >>> print str1.split('.',1)
18 ['3w', 'gorly.test.com.cn']
19 
20 #指定分隔符为'.',并且指定切割次数为2次
21 >>> print str1.split('.',2)
22 ['3w', 'gorly', 'test.com.cn']
23 
24 #这种分割等价于不指定分割次数str1.split('.')情况
25 >>> print str1.split('.',-1)
26 ['3w', 'gorly', 'test', 'com', 'cn']
27 
28 #指定分隔符为'.',并取序列下标为0的项
29 >>> print str1.split('.')[0]
30 3w
31 
32 #指定分隔符为'.',并取序列下标为4的项
33 >>> print str1.split('.')[4]
34 cn 

View Code

转自:python·那些不值钱的经验 (转)

 python操作yaml文件

转自:https://blog.csdn.net/lmj19851117/article/details/78843486(python yaml用法详解)

参考:https://blog.csdn.net/legendary_Dragon/article/details/80927881(如何安装Python的yaml包)

python操作json文件

转自:python·那些不值钱的经验(python json模块 超级详解)

python实现计算机屏幕水印

地址:https://blog.csdn.net/kk185800961/article/details/79296315

利用Python爬取网页图片

地址:python·那些不值钱的经验

python爬虫

地址:https://blog.csdn.net/jsmok_xingkong/article/details/78448932

地址:https://blog.csdn.net/csqazwsxedc/article/details/68498842

python爬虫常用第三方库

地址:https://blog.csdn.net/woshisunchi/article/details/60877817

[python]pip常用命令

地址:python·那些不值钱的经验

非官方的Windows二进制文件Python扩展包(★★★★☆)

地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/

Python正则表达式指南

地址:python·那些不值钱的经验

Python的.py文件打包成exe可执行文件

地址:python·那些不值钱的经验

–the end–

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/34675.html

(0)
上一篇 2024-01-23 22:26
下一篇 2024-01-24 14:26

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信