+ 1
what is difference between u1,u2= input (). split() and taking input like u1=input() u2=input()
18 ответов
+ 17
Amit Joe
You can see the difference by printing the statements in code playground...
u1,u2=input().split()
Will take two input in one line
u1=input()
u2=input ()
Will take input in two new lines
+ 7
Amit Joe ,
Both the way string concatenation is possible
you can try that in code playground...
+ 7
Aditya Dixit, people are here to learn, not to be confused.
Before you insist that something works, go and actually try it out - there's always the Code Playground.
Lists clearly have no split method, and a simple experiment will show you that immediately.
+ 4
u1,u2= input (). split()
Reads input as a single line and splits it on white space. For example, if input is:
hi bye
... then u1 is 'hi' and u2 is 'bye'.
u1=input()
u2=input()
Reads two values from exactly two input lines. For example, if input is:
3
4
... then u1 is '3' and u2 is '4'
+ 4
Aditya Dixit
Still incorrect. Your first reference link is broken and the other 2 describes split() method for strings, which was what I tried explaining to you.
The output of your code is wrong as well. Please do some research and test out your code before posting incorrect info.
https://code.sololearn.com/csDem7IEAOUU/?ref=app
+ 4
Maybe best to split it up (no pun intended).
What the a, b =... syntax does is take the elements of some container and put them in separate variables.
So you could also write:
u1, u2 = [input(), input()]
First, two inputs are taken, then they're put into a list, then the list's elements are put into two separate variables.
Now the split method creates a list, by cutting up one string. (Input is always a string.)
So with input().split(), you take ONE input and directly cut it into pieces, which are then stored in a list.
+ 4
Aditya Dixit
I was wondering where your code examples come from. After playing around with chatGPT the bot gave me more or less the same example.
But, that's why I'm writing you, you need to test each code examples. That's really important. The bot is not perfect and there is a reason why stackoverflow does not allow copy&paste answers from the bot.
So, test each code and ask the bot questions if you think there is a mistake. But do not just copy and paste.
+ 3
Aditya Dixit
Your answer is not correct. The `.split()` method being discussed here belongs to the str class, which means it can only operate on a string.
https://docs.python.org/3.8/library/stdtypes.html#string-methods
There is no split() function that can be used on lists and tuples.
https://docs.python.org/3.8/tutorial/datastructures.html
+ 2
Among other stuff, this is literally what you wrote:
list1 = [1, 2, 3, 4, 5, 6]
list2 = list1.split(3)
print(list2)
# Output: [[1, 2], [4, 5, 6]]
Come on, dude.
+ 2
Well, Aditya Dixit, we can at least judge your behavior here in this thread, and two things stand out:
1.) You made a mistake and spent many posts trying to distract from that and even claiming you were correct, although a simple check shows everybody that what you suggested is wrong in a very basic way.
2.) It turned out the nonsense you were writing about Python in a very confident style for whatever reason exactly matches the wrong answer chatGPT gives - probably not much longer though because opposed to you chatGPT is willing to learn and admit mistakes.
Why are you here on Sololearn? Are you here to learn something, or do you just want to get praised for what you're writing, even if it's demonstrably bollocks?
+ 1
The difference between u1,u2= input().split() and taking input like u1=input() u2=input() in python is that the former allows you to take two inputs at the same time while the latter requires two separate lines of code to take two inputs.
+ 1
u1,u2= input (). split()
Reads input as a single line and splits it on white space. So if we wright hello world as the input u1 is hello u2 is world.
u1=input()
u2=input()
It will be on different lines
0
ok n thanks
0
split function takes string only no other data types??
0
No, the Python split() function can also be used to split other data types, such as lists and tuples.
0
The Python split() function can be used to split other data types, such as lists and tuples. For example, you can split a list into a list of sublists using the split() function:
list1 = [1, 2, 3, 4, 5, 6]
list2 = list1.split(3)
print(list2)
# Output: [[1, 2], [4, 5, 6]]
Similarly, you can split a tuple into a tuple of sub-tuples using the split() function:
tup1 = (1, 2, 3, 4, 5, 6)
tup2 = tup1.split(3)
print(tup2)
# Output: ((1, 2), (4, 5, 6))
For more information about the Python split() function, see the following resources:
- https://www.geeksforgeeks.org/python-split-function/
- https://www.w3schools.com/python/ref_string_split.asp
- https://docs.python.org/3/library/stdtypes.html#string-methods
0
Well... it's my hard work to get upto this level and not any ai crap you talking about if you don't know someone then don't judge