Answers for "line.split"

24

split string python

file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
Posted by: Guest on April-01-2020
0

how to use a split

>>> score1,score2 = input("Enter two scores separated by a comma:").split(",")
Enter two scores separated by a comma:1,2
>>> score1
'1'
>>> score1 = int(score1)
>>> score1
1
>>> score1 = float(score1)
>>> score1
1.0
>>>
Posted by: Guest on July-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language