{"id":2314,"date":"2026-09-30T13:03:22","date_gmt":"2026-09-30T13:03:22","guid":{"rendered":"https:\/\/entri.app\/explore\/?post_type=curriculum&#038;p=2314"},"modified":"2026-09-30T13:03:22","modified_gmt":"2026-09-30T13:03:22","slug":"python-input-function","status":"publish","type":"curriculum","link":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/","title":{"rendered":"Python Input Function"},"content":{"rendered":"<p>To take input in Python, use the built-in <strong><b>input()<\/b><\/strong>\u00a0function: name = input(&#8220;Enter your name: &#8220;). It pauses the program, shows the prompt, waits for the user to type and press Enter, and returns what they typed <strong><b>as a string<\/b><\/strong>. To get a number, convert the result with int()\u00a0or float().<\/p>\n<h2><strong><b>What Is the input() Function in Python?<\/b><\/strong><\/h2>\n<p><strong><b>input()<\/b><\/strong>\u00a0is a built-in function that reads one line of text from the keyboard (standard input). Its syntax is input(prompt), where the optional prompt is a message shown to the user.<\/p>\n<ul>\n<li>It always returns a <strong><b>str<\/b><\/strong>, even if the user types 42.<\/li>\n<li>The trailing Enter key (newline) is removed from the result.<\/li>\n<li>The program is paused until the user presses Enter.<\/li>\n<\/ul>\n<h2><strong><b>How to Take User Input in Python (Strings)<\/b><\/strong><\/h2>\n<p>Because input() already returns a string, taking string input needs no conversion:<\/p>\n<p>name = input(&#8220;Enter your name: &#8220;)<\/p>\n<p>print(f&#8221;Welcome, {name}!&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p># Run:<\/p>\n<p># Enter your name: Rahul<\/p>\n<p># Welcome, Rahul!<\/p>\n<p>To &#8220;give&#8221; input, run the script in a terminal or IDE, type your value after the prompt, and press Enter. In Jupyter, a text box appears below the cell.<\/p>\n<h2><strong><b>How to Take Integer Input in Python<\/b><\/strong><\/h2>\n<p>Wrap input() in int()\u00a0for whole numbers or float()\u00a0for decimals:<\/p>\n<p>age = int(input(&#8220;Enter your age: &#8220;))<\/p>\n<p>price = float(input(&#8220;Enter price: &#8220;))<\/p>\n<p>print(age + 1, price * 2)<\/p>\n<p>If the user types something that is not a number, int()\u00a0raises ValueError. Handle it with try\/except (see the Exception Handling topic).<\/p>\n<h2><strong><b>How to Take List Input in Python<\/b><\/strong><\/h2>\n<p>The most common method: read the whole line, split()\u00a0it into parts, and convert each part:<\/p>\n<p># User types: 10 20 30<\/p>\n<p>nums = list(map(int, input(&#8220;Enter numbers: &#8220;).split()))<\/p>\n<p>print(nums) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# [10, 20, 30]<\/p>\n<p>&nbsp;<\/p>\n<p># Comma-separated: apple,banana,mango<\/p>\n<p>fruits = input(&#8220;Enter fruits: &#8220;).split(&#8220;,&#8221;)<\/p>\n<p>print(fruits) \u00a0\u00a0\u00a0\u00a0\u00a0# [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;mango&#8217;]<\/p>\n<p>Alternatively, ask for the count first and read one item per line with a loop:<\/p>\n<p>n = int(input(&#8220;How many items? &#8220;))<\/p>\n<p>items = []<\/p>\n<p>for i in range(n):<\/p>\n<p>items.append(input(f&#8221;Item {i+1}: &#8220;))<\/p>\n<p>print(items)<\/p>\n<h2><strong><b>How to Build a Simple Calculator Using input() in Python<\/b><\/strong><\/h2>\n<p><strong><b>Part 2 \u2014 Tutorial<\/b><\/strong><\/p>\n<p>In this tutorial you will build a calculator that reads two numbers and an operator from the user with input(), converts them, and prints the result. It takes about 15 minutes and 5 steps and uses input(), float(), if\/elif and print().<\/p>\n<h3><strong><b>Prerequisites<\/b><\/strong><\/h3>\n<ul>\n<li>Python 3 installed and able to run a script from the terminal.<\/li>\n<li>Basic understanding of variables and print().<\/li>\n<\/ul>\n<h3><strong><b>Steps<\/b><\/strong><\/h3>\n<p><strong><b>Step 1: Read the first number<\/b><\/strong><\/p>\n<p>Convert the text to float so decimals work.<\/p>\n<p>a = float(input(&#8220;First number: &#8220;))<\/p>\n<p><strong><b>Step 2: Read the operator as a string<\/b><\/strong><\/p>\n<p>No conversion is needed; strip() removes accidental spaces.<\/p>\n<p>op = input(&#8220;Operator (+ &#8211; * \/): &#8220;).strip()<\/p>\n<p><strong><b>Step 3: Read the second number<\/b><\/strong><\/p>\n<p>Same conversion as step 1.<\/p>\n<p>b = float(input(&#8220;Second number: &#8220;))<\/p>\n<p><strong><b>Step 4: Calculate with if\/elif<\/b><\/strong><\/p>\n<p>Check the operator and guard against division by zero.<\/p>\n<p>if op == &#8220;+&#8221;:<\/p>\n<p>result = a + b<\/p>\n<p>elif op == &#8220;-&#8220;:<\/p>\n<p>result = a &#8211; b<\/p>\n<p>elif op == &#8220;*&#8221;:<\/p>\n<p>result = a * b<\/p>\n<p>elif op == &#8220;\/&#8221; and b != 0:<\/p>\n<p>result = a \/ b<\/p>\n<p>else:<\/p>\n<p>result = &#8220;Invalid input&#8221;<\/p>\n<p><strong><b>Step 5: Print the result<\/b><\/strong><\/p>\n<p>Display it with an f-string, then run the script and test it with different inputs.<\/p>\n<p>print(f&#8221;Result: {result}&#8221;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To take input in Python, use the built-in input()\u00a0function: name = input(&#8220;Enter your name: &#8220;). It pauses the program, shows the prompt, waits for the user to type and press Enter, and returns what they typed as a string. To get a number, convert the result with int()\u00a0or float(). What Is the input() Function in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"template":"","meta":{"_acf_changed":false},"curriculum-category":[150,149,148],"custom_linking_tags":[],"class_list":["post-2314","curriculum","type-curriculum","status-publish","hentry","curriculum-category-python-foundations","curriculum-category-python-tutorials","curriculum-category-python-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Input Function<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Input Function\" \/>\n<meta property=\"og:description\" content=\"To take input in Python, use the built-in input()\u00a0function: name = input(&#8220;Enter your name: &#8220;). It pauses the program, shows the prompt, waits for the user to type and press Enter, and returns what they typed as a string. To get a number, convert the result with int()\u00a0or float(). What Is the input() Function in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Free Materials\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/\",\"url\":\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/\",\"name\":\"Python Input Function\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/explore\/#website\"},\"datePublished\":\"2026-09-30T13:03:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/explore\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Input Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/explore\/#website\",\"url\":\"https:\/\/entri.app\/explore\/\",\"name\":\"Entri Free Materials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/explore\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/explore\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/explore\/#organization\",\"name\":\"Entri Free Materials\",\"url\":\"https:\/\/entri.app\/explore\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg\",\"contentUrl\":\"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg\",\"caption\":\"Entri Free Materials\"},\"image\":{\"@id\":\"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Input Function","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/","og_locale":"en_US","og_type":"article","og_title":"Python Input Function","og_description":"To take input in Python, use the built-in input()\u00a0function: name = input(&#8220;Enter your name: &#8220;). It pauses the program, shows the prompt, waits for the user to type and press Enter, and returns what they typed as a string. To get a number, convert the result with int()\u00a0or float(). What Is the input() Function in [&hellip;]","og_url":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/","og_site_name":"Entri Free Materials","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/","url":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/","name":"Python Input Function","isPartOf":{"@id":"https:\/\/entri.app\/explore\/#website"},"datePublished":"2026-09-30T13:03:22+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/explore\/python-programming\/python-input-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/explore\/python-programming\/python-input-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/explore\/"},{"@type":"ListItem","position":2,"name":"Python Input Function"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/explore\/#website","url":"https:\/\/entri.app\/explore\/","name":"Entri Free Materials","description":"","publisher":{"@id":"https:\/\/entri.app\/explore\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/explore\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/explore\/#organization","name":"Entri Free Materials","url":"https:\/\/entri.app\/explore\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/","url":"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg","contentUrl":"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg","caption":"Entri Free Materials"},"image":{"@id":"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/curriculum\/2314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/curriculum"}],"about":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/types\/curriculum"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/users\/2"}],"wp:attachment":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/media?parent=2314"}],"wp:term":[{"taxonomy":"curriculum-category","embeddable":true,"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/curriculum-category?post=2314"},{"taxonomy":"custom_linking_tags","embeddable":true,"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/custom_linking_tags?post=2314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}