跟我一起学python(2)
学习总结:
1、数据类型
a、数据:表示一种状态
b、python不存在字符类型
c、可变与不可变

d、x = 10 既 x = int(10)

2、字符编码
3、文件处理
详细:
数据类型:
is关键字 内存空间是否一样 x = 12 y=13 x is y False
m=123 n=123 id(n) id(m) 一样 m is n True 因为python对于数据量小的情况下 都占用同一块空间
字符串:
优先掌握的操作:
按索引取值:
name = "egon";
print(name[0],type(name[0]));
print(name[-2]);
切片(顺头不顾尾,步长):
msg = "hello world";
print(msg[::-1]);
长度(len)--- 数字没有长度,字符串有长度
lenTest = "你好?怎么说呢";
print(len(lenTest));
成员运算 In not in
msg1 = "hello yangtong";
print("llo " in msg1);
移除空白 strip
//23423 234234
password = " 23423 234234 "
print(password.strip());
//23423 234234
password = "*********23423 234234**************"
print(password.strip("*"));
切分 split
user_info = "root:x:0:0:/root:/bin/bash"
print(user_info.split(":")[0]);
cmd = "put a.txt";
print(cmd.split())
filepath = "put /a/b/c/d/a.txt";
print(filepath.split(maxsplit = 1))
次要掌握的操作:
msg = " yangtong ";
print(msg.lstrip())
print(msg.rstrip())
什么开头 什么结尾
msg = "jiangziya_SB";
print(msg.startswith("jiangziya"));
print(msg.endswith("SB"))
replace
msg = "haohao have a girl,haohao is good;"
print(msg.replace("haohao","tong",1));
占位
print("%s %s" %('',123));
print("{} {}".format('',123))
print('{1}{0}'.format('',15))
print('{x},{y}'.format(y=13,x='hello'));
find rfind与index rindex
msg = "hello world"
# 是否有子字符串 相当于indexOf
print(msg.find('ell'))
# 找不到会报错 其他的和find一样
print(msg.index(''))
count
msg = 'hello world'
# 范围 顾头不顾尾
print(msg.count('l',0,4));
join
user_info = "root:x:0:0:asdasd"
l = user_info.split(":");
print(l);
test = ':'.join(l);
# 拼接按制定符号连接到一起
print(test);
center ljust rjust zerofill
user_info = "hello"
# ============hello=============
# =========================hello
# hello=========================
# 0000000000000000000000000hello
print(user_info.center(30,"="));
print(user_info.rjust(30,"="));
print(user_info.ljust(30,"="));
print(user_info.zfill(30));
其他
msg = "sdlfkj\tsdsdfsd"
# 控制制表符有几个
# sdlfkj sdsdfsd
print(msg.expandtabs(10))
msg = "abc bcd ksk"
# Abc bcd ksk
# ABC BCD KSK
# abc bcd ksk
# Abc Bcd Ksk
# ABC BCD KSK
print(msg.capitalize())
print(msg.upper());
print(msg.lower())
print(msg.title())
print(msg.swapcase())
跟我一起学python(2)的更多相关文章
- 【Python五篇慢慢弹】快速上手学python
快速上手学python 作者:白宁超 2016年10月4日19:59:39 摘要:python语言俨然不算新技术,七八年前甚至更早已有很多人研习,只是没有现在流行罢了.之所以当下如此盛行,我想肯定是多 ...
- <-0基础学python.第一课->
初衷:我电脑里面的歌曲很久没换了,我想听一下新的歌曲,把他们下载下来听,比如某个榜单的,但是一首一首的点击下载另存为真的很恶心 所以我想有没有办法通过程序的方式来实现,结果还真的有,而且网上已经有有人 ...
- 学Python后到底能干什么?
Python是一种什么语言? Python是一种计算机程序设计语言.你可能已经听说过很多种流行的编程语言,比如非常难学的C语言,非常流行的Java语言,适合初学者的Basic语言,适合网页编程的Jav ...
- 关于智普 - 千人免费学|Python培训|国内最权威python培训|html5
关于智普 - 千人免费学|Python培训|国内最权威python培训|html5 智普教育隶属于北京顶嵌开源科技有限公司,成立于2008年. 智普开源是基于Linux系统的互联网开源学习平台,讲求务 ...
- [置顶] 和孩子们一起学Python编程
1. 推荐书名 Computer Programming for Kids and Other Beginners in Python, 4Ed.pdf 中文译名:<和孩子们一起学Pyt ...
- 简学Python第二章__巧学数据结构文件操作
#cnblogs_post_body h2 { background: linear-gradient(to bottom, #18c0ff 0%,#0c7eff 100%); color: #fff ...
- 简学Python第一章__进入PY的世界
#cnblogs_post_body h2 { background: linear-gradient(to bottom, #18c0ff 0%,#0c7eff 100%); color: #fff ...
- 一步一步学Python(2) 连接多台主机执行脚本
最近在客户现场,每日都需要巡检大量主机系统的备库信息.如果一台台执行,时间浪费的就太冤枉了. 参考同事之前写的一个python脚本,配合各主机上写好的shell检查脚本,实现一次操作得到所有巡检结果. ...
- 为什么要学Python
人生苦短,我用python.在大学四年的本科学习中,Python是我接触过语法最简单,功能最为强大的语言,拥有众多第三方库的支持的语言.如果要选一门编程语言作为入门,建议使用Python.但是为了更加 ...
- C语言老司机学Python (五)
今天看的是标准库概览. 操作系统接口: 用os模块实现. 针对文件和目录管理,还有个shutil模块可以用. 例句: import os os.getcwd() # 返回当前的工作目录 os.chdi ...
随机推荐
- python爬虫遇到https站点InsecureRequestWarning警告解决方案
python爬虫遇到https站点InsecureRequestWarning警告解决方案 加三行代码即可 from requests.packages.urllib3.exceptions impo ...
- STL 中 使用迭代器删除元素的问题
在vector中删除,大家都知道,直接erase的话,这种写法很有问题.因为erase(iter)之后iter指针就变成野指针了,此时继续iter++就会出问题. for(auto iter = v. ...
- java实现单链表反转(倒置)
据说单链表反转问题面试中经常问,而链表这个东西相对于数组的确稍微难想象,因此今天纪录一下单链表反转的代码. 1,先定义一个节点类. 1 public class Node { 2 int index; ...
- vue_过滤器: 对要显示的数据进行特定格式化后再显示
过滤器 对要显示的数据进行特定格式化后再显示 并未改变原本的数据,可是产生新的对应的数据 <!DOCTYPE html> <html lang="en"> ...
- python开发之virtualenv与virtualenvwrapper讲解
在使用 Python 开发的过程中,工程一多,难免会碰到不同的工程依赖不同版本的库的问题: 亦或者是在开发过程中不想让物理环境里充斥各种各样的库,引发未来的依赖灾难. 此时,我们需要对于不同的工程使用 ...
- Could not find artifact cn.e3mall:e3mall-parent:pom:0.0.1-SNAPSHOT
[ERROR] [ERROR] Some problems were encountered while processing the POMs:[FATAL] Non-resolvable pare ...
- Float.intBitsToFloat
Float.intBitsToFloat(0b) Float.intBitsToFloat(0) Float.intBitsToFloat(0x) ========================== ...
- Ringo替换Paul
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 前台js根据当前时间生成订单号
*********前台显示框**************** <input type="text" id="WIDout_trade_no" name=& ...
- python 科学计算与可视化
一.Numpy 库 NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库. 引用: import ...