I was wondering if there is a similar functionality take an input from user in python similar to taking the input from user in 'C' using scanf().
Asked
Active
Viewed 4.9k times
-1
Blade
- 838
- 10
- 29
Andy.inamdar
- 175
- 1
- 2
- 10
-
1`input()` in Python 3, `raw_input()` in Python 2. – Barmar Jan 18 '17 at 17:16
-
4This has to be explained in most tutorials. – Barmar Jan 18 '17 at 17:16
-
a tutorial: http://python3porting.com/differences.html#input-and-raw-input – chickity china chinese chicken Jan 18 '17 at 17:21
-
dont ask me the que dude... – Andy.inamdar Jan 18 '17 at 17:38
-
OP should probably delete this question, which will regain rep. – ti7 Jan 25 '18 at 20:19
-
3This is not a duplicate IMO, scanf is a very specific tool and I don't think `raw_input` will cover all of its functionalities – radrow Jan 02 '20 at 12:37
-
I agree with @radrow, in python you can't read in a formatted style, like `scanf("%d %f", &my_int, &my_float)`. In python after reading with input() you should parse every entry in the input to typecast and assign variables. – Jader Martins Apr 21 '22 at 23:27
-
@Barmar `input()` or `raw_input()` is similar to `gets` but OP is asking for `scanf`. – tsh May 03 '22 at 11:10
-
@tsh The question is so vague it's hard to tell what they're really asking for. – Barmar May 03 '22 at 13:54
-
@Barmar I think it is clear enough. Python have a string format operator `'%d, %d' % (3, 4) ` which works just like what `printf` (or say, `sprintf`) do. So it could be easy to Python beginners with C background to ask "if there are something similar to `scanf`". Should OP include what `scanf` do (maybe copy [what `man` says](https://linux.die.net/man/3/scanf)) in the post so it become clear? – tsh May 03 '22 at 17:25
2 Answers
2
input(). For example this could be used as:
Name = input("Please enter your name?")
For use in Python 2, this would be raw_input(). For example this could be used as:
Name = raw_input("Please enter your name?")
Blade
- 838
- 10
- 29
CodeCupboard
- 1,388
- 2
- 16
- 25
-1
in Python 2, you can use input() or raw_input()
s = input() // gets int value
k = raw_input() // gets string value
user8484322
- 3
- 3
OzizLK
- 49
- 2
- 11