简体   繁体   中英

c has scanf, does python have something similar?

I am trying to solve problems from SPOJ. I need to be able to read input from stdin for that, I did a lot of problems in C using scanf but wanted to try Python as well. How do i read the stdin inputs in Python? (wanna use Python 2.6/2.7)

In Python 2.7

  • To get integers or floats as inputs you can use the key word 'input' Example: temp=input("Give your value") Here temp only takes a float or int

  • There is another command raw_input() any value that raw input is given it converts it to string and assigns the value Example:temp=raw_input("Give your value") Here temp is of string type

For what I researched, in python 2.7(in all versions of python 2) the command of input is: raw_input( )

in this link have a tutorial about this: https://linuxconfig.org/how-to-obtain-an-user-input-with-python-raw-input-function-example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM