自学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 ...
随机推荐
- oc58--Category注意事项
// // main.m // Category注意事项 #import <Foundation/Foundation.h> #import "Person+NJ.h" ...
- Why is try {…} finally {…} good; try {…} catch{} bad?
http://stackoverflow.com/questions/128818/why-is-try-finally-good-try-catch-bad The big difference i ...
- 为什么倒排索引不采用zlib这样的字典压缩算法——因为没法直接使用啊
看了下压缩算法的发展历史,根据倒排索引的数据结构特点,个人认为zstd不适合做倒排索引压缩,举例说明下: 假设有一份文档倒排列表为:[300, 302, 303, 332],对于这组倒排数据,是没法* ...
- 2017 Multi-University Training Contest - Team 2 &&hdu 6050 Funny Function
Funny Function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 爆搜
这题怎么这么水~~~本来以为挺难的一道题,结果随便一写就过了...本来还不知道损坏的牛棚算不算,结果不明不白就过了... 题干: 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有 ...
- 阿里云centos系统上安装ftp
最近需要在一台阿里云的云服务器上搭建FTP服务器,在这篇博文中分享一下我们根据实际需求进行的一些配置. ftp软件用的是vsftpd. vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- BZOJ 2333 左偏树 (写得我人生都崩溃了...)
思路: 高一神犇 竟然 问我这道题 我光荣地 看着题解(划掉) 写了一下午 QaQ multiset不能erase(一个值) 这样就把等于这个值 的数都erase掉了 (woc我一开始不 ...
- POJ 1101 译文
The Game 题意: Description One morning, you wake up and think: "I am such a good programmer. Why ...
- 好用的Cache辅助工具类
话不多说,直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- dotnet core 发布配置(测试数据库和正式数据库自动切换)
一.起源 在进行项目开发时,常常要求开发环境,测试环境及正式环境的分离,并且不同环境运行的参数都是不一样的,比如监听地址,数据库连接信息等.当然我们把配置信息保存到一个文件中,每次发布的时候,可以先修 ...