Python Input Related

Asked 2 years ago, Updated 2 years ago, 14 views

s = list(map(str, input().split()))

Department

s = list(input().split())

I wonder what the difference is in the process of receiving these two inputs

python

2022-09-20 19:48

1 Answers

There's no difference

Since input() is received in str form from Python3, there is no need to set it as str on the map.

Please refer to the example I wrote below.

Please refer to the link https://wikidocs.net/32#map

class test:
    def __init__(self, param):
        self.num = param
    def __str__(self):
        return self.num

a = 'input something'.split()
r = map(test,a)
r = list(r)  #not necessary

for i in r:
    print(i)

#input
#something

def func(param):
    r = ''
    for i in param:
        r += chr(ord(i)+1)
    return r

a = 'abc def ghi'.split()
r = map(func, a) 
r = list(r) #not necessary

for i in r:
    print(i)

#bcd
#efg
#hij


2022-09-20 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.