自学python 第三天
#!/usr/bin/env python
# -*- coding:utf-8 -*- # name = "***"
# if "*" in name:
# print('帅哥')
# else: # a = 123
#
# v = a.bit_length()
# print(v)
#type表示类型,(具体字符还是,数字)
# a = "999"
# print(type(a),a)
# b = int(a)
# print(type(b),b)
#base是表示多少进制
# num = "0011"
# v= int(num,base=8)
# print(v) # name = "sdadhsja"
# age = "18"
# info = name + age
# print(info) sdadhsja18 #**********一个深灰魔法***************
# 字符串一旦创建就不可修改
# 一旦修改或者拼接,都会造成重新生成字符串 #******7个基本魔法*******
# join 加入
# split 分割
# find 查找
# strip 去除
# upper 转换为大写字母
# lower 转换为小写字母
# replace 替换
# test = "alexalexalex"
# v = test.replace("ex",'cc',2)
# print(v) alccalccalex
#******4个灰魔法*******
# test = "alex"
# v = test[3] 索引,下标,获取字符窜中的某一个字符
# print(v) x
#字符(.format)的用法 # test = "alex"
# v = test[0:2] 0<= <1 【切片】
# print(v) al
# test = "alex"
# v = len(test) 获取当前字符窜中由几个字符组成【Python3】
# print(v)
#注意: 在其他语言中也有用法
# len("sdas")
# "__".join("skahdaidja")
#test = "计算机的发展史没有很"
#
# index = 0
# while index<len(test):
# v = test[index]
# print(v)
#
# index += 1
# print('======')
# 计
# 算
# 机
# 的
# 发
# 展
# 史
# 没
# 有
# 很
# ======
# for 循环 【for变量名 in 字符串:】 【索引,切片也能用】
# 变量名
# test = "郑建文妹子有种冲我来"
# for zjw in test:
# print(zjw)
# 郑
# 建
# 文
# 妹
# 子
# 有
# 种
# 冲
# 我
# 来 # test = 'i am {name},age{a}' name,age。可以换成0,1
# print(test)
# v = test.format(name='alex',a='19')
# print(v) # 字符(.find)的用法 从开始往后找,找打第一个之后 ,获取位置(位置可以自己定义)
# test ="alexalex"
# v = test.find('x',5,8) (表示从几位开始到几位结束)
# print(v) (当找不到时,会显示‘-1’) #字符.index的用法 (当找不到时会报错)
# test = "alexalex"
# v = test.index('x')
# print(v) #字符(.isalnum)的用法 (字符窜中只能包含 数字和字母)
# test = "usdsad"
# v = test.isalnum()
# print(v) #字符(.isalpha的用法) (字符窜中只能包含 汉字 和 字母)
# test = "sdafas可以"
# v = test.isalpha()
# print(v) #字符(.expandtabls)的用法
# test = "username\temail\tpassword\nycj\tyang@qq.com\t123"
# v = test.expandtabs(20)
# print(v) # 字符(.isdcimal)的用法 (当前输入是否是数字)
# test = "254655"
# v1 =test.isdecimal()
# v2 =test.isdigit()
# print(v1,v2) #字符(.swapcase)的用法 (大小字母转换,--原来是小写换为大写,原来是小写换为大写)
# test = "nsakdlsSDH"
# v = test.swapcase()
# print(v) #字符(.isidentifier) (字母,数字,汉语,下滑线:标志符 def class{除符号包括空格})
# a = "def____125你"
# v = a.isidentifier()
# print(v) #字符(.isprintable)的用法 (是否存在不可显示的字符) (/t 换行) /n
# test = "sjdh/nsdsa"
# v = test.isprintable()
# print(v)
#字符(.isprintable)的用法 是否存在不可显示的字符
# test = "skduwh\tdjshd"
# # v = test.isprintable()
# # print(v) #字符(.isspace)的用法 (判断是否全部是空格)
# test = " "
# v = test.isspace()
# print(v) #字符(.istitle) (判断是否是大写首字母开头)
# test = "Asdfsdf"
# v = test.istitle()
# print(v) #isdecimal,isdigit,isnumeric,字符的用法和区别:当前输入是否是数字
# test = "二" # 1, ②
# v1 = test.isdecimal()
# v2 = test.isdigit() ()
# v3 = test.isnumeric() (判断是否是标题的时候)
# print(v1,v2,v3) #字符(.title,.istitle)的用法 (判断是否是标题)
# test = "Return True if all cased characters in S are uppercase and there is pigman"
# v1 = test.title() #转化为单词的首字母为大写字母开头
# print(v1)
# v2 = test.istitle() #判断单词首字母是否是大写字母开头
# print(v2) #****字符(.join)的用法 (将字符窜的每一个元素按照指定的分隔符进行拼接)
# test = "你是风儿我是沙"
# print(test)
# t = ' '
# v = t.join(test)
# print(v) (你 是 风 儿 我 是 沙) #**字符(.center)的用法 (设置宽度,并将类容居中)
# test = "2000"
# v = test.center(20) (20代指总长度)
# print(v) ( 2000 ) #**字符(.ljust)的用法 (左边为字符窜,右边为填充内容)(“*”为填充内容)
# test = "abcd"
# v = test.ljust(20,"*")
# print(v) (abcd****************)
#**字符(.rjust)的用法 右边为字符窜,左边为填充内容(“*”为填充内容)
# test = "abcd"
# v = test.rjust(20,'*')
# print(v) (****************abcd)
#字符(.zfill)的用法 不能指定填充内容
# test = "alex"
# # v = test.zfill(20) #(20代指总长度)
# # print(v) (0000000000000000alex) #字符(.lower,.islower)的用法
# test = "Alex"
# v1 = test.islower() 判断是否全是小写
# v2 = test.lower() 全部转化为小写
# print(v1,v2) (False alex) #字符(.upper,isupper)的用法
# test = "Alex"
# v1 = test.isupper() (判断是否全是大写)
# v2 = test.upper() (全部转化为大写)
# print(v1,v2) (False ALEX) #字符(.lstrip,rsrip,strip) (默认去除左右空白或去除指定字母,字符)
# test = " alex "
# v1 = test.lstrip()
# v2 = test.rstrip()
# v3 = test.strip()
# print(v1,v2,v3) (alex alex alex) #字符(.maketrans)的用法 (一一对应翻译转化,字符的一种特换)
# test = "abcd"
# test1 = "1234"
# v = "kajdak;sdasx;sdasvs"
# m = str.maketrans("abcd", "1234")
# new_v = v.maketrans(m)
# print(new_v) ({97: 49, 98: 50, 99: 51, 100: 52}) # 字符(.partition,.rpartition,.split,rsplit)的用法
# test = "testasdsddfg"
# v1 = test.partition('s') #(分割只能分两份)
# v2 = test.rpartition('s') #(分割只能分三份)
# v3 = test.split('s') #(全部分割,不包含分割的元素)
# v4 = test.rsplit('s') #()
# print(v1,v2,v3,v4) ('te', 's', 'tasdsddfg') ('testasd', 's', 'ddfg') ['te', 'ta', 'd', 'ddfg'] ['te', 'ta', 'd', 'ddfg']
#正则表达式
#是否想要分割的元素
#v = test.split('s',2) #字符(.startswith)的用法
# test = "backend"
# v1 = test.startswith('b') #(以**开头,以**结尾)
# v2 = test.endswith('d')
# print(v1,v2) True True # 字符(.swaprase)的用法 大小写转换
# test = "aldaLSA"
# v = test.swapcase()
# print(v) (ALDAlsa) # test = "你是风儿我是沙"
# t = '*'
# v = t.join(test)
# print(v)
自学python 第三天的更多相关文章
- 孤荷凌寒自学python第三十九天python 的线程锁Lock
孤荷凌寒自学python第三十九天python的线程锁Lock (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 当多个线程同时操作一个文件等需要同时操作某一对象的情况发生时,很有可能发生冲突, ...
- 孤荷凌寒自学python第三十八天初识python的线程控制
孤荷凌寒自学python第三十八天初识python的线程控制 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.线程 在操作系统中存在着很多的可执行的应用程序,每个应用程序启动后,就可以看 ...
- 孤荷凌寒自学python第三十七天python的文件与内存变量之间的序列化与反序列化
孤荷凌寒自学python第三十七天python的文件与内存变量之间的序列化与反序列化 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.什么是序列化与反序列化 序列化是指将内存中的数据进行指 ...
- 孤荷凌寒自学python第三十五天python的文件操作之针对文件操作的os模块的相关内容
孤荷凌寒自学python第三十五天python的文件操作之针对文件操作的os模块的相关内容 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.打开文件后,要务必记得关闭,所以一般的写法应当 ...
- 孤荷凌寒自学python第三十四天python的文件操作对file类的对象学习
孤荷凌寒自学python第三十四天python的文件操作对file类的对象学习 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.close() 当一个file对象执行此方法时,将关闭当前 ...
- 孤荷凌寒自学python第三十三天python的文件操作初识
孤荷凌寒自学python第三十三天python的文件操作初识 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天开始自学python的普通 文件操作部分的内容. 一.python的文件打开 ...
- 孤荷凌寒自学python第三十一天python的datetime.timedelta模块
孤荷凌寒自学python第三十一天python的datetime.timedelta模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) datetime.timedelta模块是一个表示 ...
- 孤荷凌寒自学python第三十天python的datetime.datetime模块
孤荷凌寒自学python第三十天python的datetime.datetime模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) datetime.datetime模块包含了:datet ...
- 孤荷凌寒自学python第三天 初识序列
孤荷凌寒自学python第三天 初识序列 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Python的序列非常让我着迷,之前学习的其它编程语言中没有非常特别关注过序列这种类型的对象,而pyt ...
随机推荐
- VMware Workstation 集群仲裁磁盘和数据共享磁盘的创建
近期项目须要对SQL Server建立集群服务,多个SQL Server数据库建立集群服务,对外提供唯一的URL訪问地址.当主节点断电.断网后,通过心跳线将消息传递到备用节点.备用节点在3秒内接管数据 ...
- Oracle学习(12):存储过程,函数和触发器
存储过程和存储函数 l存储在数据库中供全部用户程序调用的子程序叫存储过程.存储函数. 注意:存储过程与存储函数声明变量时,用的是as 而不是declare 存储过程与存储函数差别 存储过程不带有返 ...
- tensorflow移植到ios
1.git clone到本地 git clone https://github.com/tensorflow/tensorflowxcode 2.compile static library 安装xc ...
- 新随笔(三)什么时候使用button,什么时候使用文字链接
新随笔(三)什么时候使用button.什么时候使用文字链接 你为什么在这个地方用button而不用文字链接呢? 这是刚才我问一个设计师的问题. 她抬头看我,眼神迷茫.说:"没什么为什么呀,我 ...
- 【Ubuntu】小技巧
1.在 usr/share/applications/ 中可以找到 .desktop 文件,修改其内容可以修改你的桌面快捷方式, 例如图标或者分类还可以新建你的 .desktop ,如果你安装的软件没 ...
- luogu3225 [HNOI2012]矿场搭建
题目大意 给出一个有$n(n\leq 500)$个节点的无向图,一个满足条件的点集$V$会使得对于图中的每一个节点$u$,满足路径起点为$u$终点$v\in V$的路径集合$P_u$中总存在至少两条路 ...
- OTA制作及升级过程笔记【转】
本文转载自:http://www.it610.com/article/5752570.htm 1.概述 1.1 文档概要 前段时间学习了AndroidRecovery模式及OTA升级过程,为加深理 ...
- 803E
dp dp[i][j]表示到了i赢和输的差为j 如果这位是?向dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1]转移,如果是W向dp[i-1][j-1]转移,如果是L向dp[i- ...
- SQL Server2012 T-SQL基础教程--读书笔记(5-7章)
SQL Server2012 T-SQL基础教程--读书笔记(5-7章) SqlServer T-SQL 示例数据库:点我 Chapter 05 表表达式 5.1 派生表 5.1.1 分配列别名 5. ...
- 在linux查看内存的大小
用free -m查看的结果: # free -m total used free shared buffers cached Mem: ...