Jan 03

To take multiple variable as input in python


To take multiple variables as input in a single line, we can use split() function as :

totalCities, totalPath = raw_input().split()


To take a integer variable as input, we can use int() function as :

T = int(raw_input())


When we take a variable as input using raw_input() function, python stores it as a string, so if we would like to take multiple variables as integer as input, we would have to take input as string, then convert them into integers as :

N,K = raw_input().split()
N = int(N)
K = int(K)


This can be done in a single line as well using map() function as :

N,K = map(int,raw_input().split())

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Warning: require_once(): open_basedir restriction in effect. File(/home/admin/web/stats.theserverhouse.com/public_html/owa_php.php) is not within the allowed path(s): (/home/admin/web/linuxjoy.in/public_html:/home/admin/tmp) in /home/admin/web/linuxjoy.in/public_html/index.php on line 20

Warning: require_once(/home/admin/web/stats.theserverhouse.com/public_html/owa_php.php): failed to open stream: Operation not permitted in /home/admin/web/linuxjoy.in/public_html/index.php on line 20

Fatal error: require_once(): Failed opening required '/home/admin/web/stats.theserverhouse.com/public_html/owa_php.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/admin/web/linuxjoy.in/public_html/index.php on line 20