当前位置:网站首页>Np5 formatted output (III)
Np5 formatted output (III)
2022-06-29 08:22:00 【Spiritual wanderer】
'''
Niu Niu 、 Niu Mei and Niu cola are both Nowcoder Users of , One day Nowcoder Because of some kind of wrong operation, the administrators of have added some extra white space characters to the left and right sides of their user names ( Such as space or '\t' etc. ),
Now give them one of the three names name, Please export name The original content after removing the blank characters on both sides .
'''
'''
Knowledge point :
.strip() --- Remove the spaces on both sides
.lstrip() --- Delete the left space
.rstrip() --- Delete the space on the right
.replace(" ","") --- Delete all spaces
.split() --- First segmentation ,"".join() --- And then splicing
'''
s1 = ' fdfdfds ohoi '
print(s1.strip(), s1.lstrip(), s1.rstrip(), s1.replace(' ',''),sep='\n')
# split() How to use the function
# 1. With no arguments
# split() If there are no parameters in , Function defaults to space ,tab Space character , Carriage return, etc. are used as segmentation conditions
String_0 = "www.com aaa bbb QJ6252630247.jpg"
String_1 = "www.com\taaa\tbbb\tQJ6252630247.jpg"
String_2 = "www.com\naaa\nbbb\nQJ6252630247.jpg"
a = String_0.split()
b = String_1.split()
c = String_2.split()
print(a)
print(b)
print(c)
# 2. With parameters
# split("/") When there are parameters in , Parameters will be used as segmentation conditions , Split the string , Each segment obtained is returned as an element of the list
String_0 = "www.com/aaa/bbb/QJ6252630247.jpg"
String_1 = "www.com-aaa-bbb-QJ6252630247.jpg"
String_2 = "www.com:aaa:bbb:QJ6252630247.jpg"
a = String_0.split("/")
b = String_1.split("-")
c = String_2.split(":")
print(a)
print(b)
print(c)
# 3. belt 2 Parameters
# The second parameter indicates how many times to split
String_0 = "www:com:aaa:bbb:QJ6252630247.jpg"
a = String_0.split(":", 1)
b = String_0.split(":", 2)
c = String_0.split(":", 3)
d = String_0.split(":", 4)
print(a)
print(b)
print(c)
print(d)
# 4. Get the last parameter
String_0 = "www.com/aaa/bbb/QJ6252630247.jpg"
a = String_0.split("/")[-1]
print(a)
# join() How to use the function
'''
Python There is join() and os.path.join() Two functions , The specific functions are as follows :
join(): Connection string array . The string 、 Tuples 、 Elements in the list with the specified characters ( Separator ) The connection generates a new string
os.path.join(): Combine multiple paths and return
'''
'''
1、join() function
grammar : 'sep'.join(seq)
Parameter description
sep: Separator . Can be null
seq: The sequence of elements to connect 、 character string 、 Tuples 、 Dictionaries
The above grammar is : With sep As a separator , take seq All the elements are combined into a new string
Return value : Returns a separator sep String generated after connecting elements
2、os.path.join() function
grammar : os.path.join(path1[,path2[,......]])
Return value : Combine multiple paths and return
notes : Parameters before the first absolute path will be ignored
'''
seq1 = ['hello' , 'good', 'boy' ]
print('-'.join(seq1))
import os
filepath = os.path.join('/hello/', 'good/boy/', 'doiido')
print(filepath)
边栏推荐
- dcase_util教程
- Manipulate the outer DOM in the iframe tag
- Paddlenlp general information extraction model: UIE [information extraction {entity relationship extraction, Chinese word segmentation, accurate entity markers, emotion analysis, etc.}, text error cor
- P6772 [NOI2020] 美食家(矩阵快速幂)
- [eye of depth wuenda machine learning homework class phase IV] regularization regularization summary
- Hook 簡介
- [eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables
- 关于SqlSugar的多对多的级联插入的问题(无法获取集合属性的id,导致无法维护中间表)
- Mongodb- connect to the database using the mongo/mongosh command line
- À propos de Hook
猜你喜欢
![[eye of depth wuenda machine learning homework class phase IV] regularization regularization summary](/img/24/3d0b892c0eaa330f0c69764de5da13.png)
[eye of depth wuenda machine learning homework class phase IV] regularization regularization summary

After crossing, she said that the multiverse really exists

Robotframework learning notes: introduction to robot framework and browserlibrary (playwright)

友元,静态关键字,静态方法以及对象间的关系

Stm32 usart+dma usage based on Hal Library

Blueprint basis
![[6G] collation of white paper on computing network technology](/img/a3/8e60eef55ebcd91fa6188722c87a70.png)
[6G] collation of white paper on computing network technology

一个高频问题,三种模型思维来破解此风控难题
![[eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables](/img/51/581be1bdfe7cc97193ff68d3ec5d22.png)
[eye of depth Wu Enda's fourth operation class] summary of multiple linear regression with multiple variables

Thread pool operations in cartographer
随机推荐
Interprocess communication (IPC)
AC automata
Should product managers learn from ink knife or Axure?
Development trend of garment industry | supply chain | intelligent manufacturing
802.11--802.11n协议 PHY
Protobuf binary file learning and parsing
NOR flash application layer operation
[eye of depth wuenda machine learning operation class phase IV] logic regression programming implementation
《乔布斯传》英文原著重点词汇笔记(七)【 chapter five】
Want to open a stock account, is it safe to open a stock account online-
What does Ali's 211 mean?
Speech signal processing - Fundamentals (I): basic acoustic knowledge
Flutter file read / write -path_ provider
Solidity deploy and validate agent contracts
想炒股开户,在网上进行股票开户安全吗?-
【6G】算力网络技术白皮书整理
语音合成:概述【不等长序列关系建模的生成任务】
《动手学深度学习》(一)-- 线性神经网络
Reflection - project management thinking of small and medium-sized companies - make the products first and the functions first
MySQL按天/周/月/季度/半年/年统计数据