当前位置:网站首页>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)
边栏推荐
猜你喜欢
![[quantitative investment system] factor processing and installation Talib](/img/33/1b8776a392c37f4d32d3bfbb3f9fd4.png)
[quantitative investment system] factor processing and installation Talib

Swift中@dynamicMemberLookup和callAsFunction特性实现对象透明代理功能

消息中间件:pulsar

802.11--802.11n协议 PHY

关于组织2021-2022全国青少年电子信息 智能创新大赛西北赛区(陕西)复赛的通知

Soliciting articles and contributions - building a blog environment with a lightweight application server

Linear regression with one variable
![[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

Matlab 用法

《动手学深度学习》(一)-- 线性神经网络
随机推荐
sql语句concat搜索不出结果
Exercise - select sort
Protobuf binary file learning and parsing
Automatic operation and maintenance management platform - construction and daily use of SPuG
自动化运维管理平台——spug的搭建和日常使用
【Redis】Redis6学习框架思路和细节
Automated test - uiautomator2 framework application - automatic clock in
练习-选择排序
1284_FreeRTOS任务优先级获取实现分析
Why are two SQL statements that execute very fast, especially after the Union
Flutter file read / write -path_ provider
想炒股开户,在网上进行股票开户安全吗?-
特征选择:最大信息系数(MIC;Maximal Information Coefficient)【用于衡量两个变量X和Y之间的关联程度,线性或非线性的强度,常用于机器学习的特征选择】
Debugging nocturnal simulator with ADB command
VMware vcenter/esxi series vulnerability summary
[quantitative investment system] factor processing and installation Talib
Seven common sorts
关于组织2021-2022全国青少年电子信息 智能创新大赛西北赛区(陕西)复赛的通知
互斥量互斥锁
Development trend of garment industry | supply chain | intelligent manufacturing