{"id":3584,"date":"2023-08-11T15:40:41","date_gmt":"2023-08-11T15:40:41","guid":{"rendered":"https:\/\/www.copahost.com\/blog\/?p=3584"},"modified":"2023-08-11T15:40:44","modified_gmt":"2023-08-11T15:40:44","slug":"input-python","status":"publish","type":"post","link":"https:\/\/www.copahost.com\/blog\/input-python\/","title":{"rendered":"Input python: How to validate and manipulate user data"},"content":{"rendered":"\n<p>Inputting data is a fundamental part of any program, and the input function in Python provides an easy way to get input from the user . Thus, this function allows the programmer to ask the user to enter an input, which can be a <a href=\"https:\/\/www.copahost.com\/blog\/string-python\/\">string<\/a> , an integer number, decimal or a string with numerical digits, among other types of data.<br><br>The &#8216;input()&#8217; function is one of the most commonly used functions in Python, as it is an easy way to get information from the user to use in a variety of programs, from simple scripts to complex applications. In addition, Python offers a variety of ways to get user data, including reading from files and manipulating data from external sources such as APIs and databases.<br><br>So this article will explore how to use the &#8216;input()&#8217; function in Python , including the different types of input you can collect and how to validate and manipulate this data for use in your programs. In addition, we&#8217;ll discuss advanced Python input techniques, such as using regular expressions for input validation and accessibility of input data in dictionaries.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_69_1 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Input_function_syntax_in_Python\" title=\"Input function syntax in Python\">Input function syntax in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Input_Validation_in_Python\" title=\"Input Validation in Python\">Input Validation in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Accessing_input_value_in_a_dictionary_in_Python\" title=\"Accessing input value in a dictionary in Python\">Accessing input value in a dictionary in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Usage_examples_for_simple_programs\" title=\"Usage examples for simple programs\">Usage examples for simple programs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Input_types_in_Python\" title=\"Input types in Python\">Input types in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Advanced_input_techniques_in_Python\" title=\"Advanced input techniques in Python\">Advanced input techniques in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#mportant_considerations_when_using_input_in_Python_programs\" title=\"mportant considerations when using input in Python programs\">mportant considerations when using input in Python programs<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input_function_syntax_in_Python\"><\/span>Input function syntax in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Python&nbsp;function&nbsp;<code>input()<\/code>&nbsp; is used to get a line input from the user&#8217;s screen.&nbsp;The basic syntax is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>response = input(\"search for something: \")<\/code><\/pre>\n\n\n\n<p>Where \u201cSearch for something\u201d is a string shown on the user&#8217;s screen to type the answer.&nbsp;Thus, function&nbsp;&nbsp;<code>input()<\/code>&nbsp;returns the string typed by the user and stores it in the variable&nbsp;&nbsp;<code>resposta<\/code>.<\/p>\n\n\n\n<p>You can also specify a format for the input, such as an integer, using the&nbsp;&nbsp;<code>int(resposta)<\/code>&nbsp;or&nbsp; syntax&nbsp;<code>float(resposta)<\/code>.&nbsp;For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>number = int(input(\"Enter an integer: \"))<\/code><\/pre>\n\n\n\n<p>Or<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>can = float(input(\"Enter a decimal position: \"))<\/code><\/pre>\n\n\n\n<p>Also, the function&nbsp;&nbsp;<code>input()<\/code>&nbsp;returns an empty string (&nbsp;<code>\"\"<\/code>) if there is no input provided by the user.&nbsp;You can use the expression&nbsp;&nbsp;<code>if resposta == \"\"<\/code>&nbsp;to check whether the input was provided or not.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>response = input(\"search for something: \")\nif response == \"\":\n    print(\"No input provided\")\nelse:\n    print(\"Response:\", response)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input_Validation_in_Python\"><\/span>Input Validation in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Input validation in Python is an important technique for ensuring that your program receives valid, human-readable input.&nbsp;This is especially important when the program is intended for end users to use, as user input is unpredictable and erroneous.<\/p>\n\n\n\n<p>There are many ways to validate input in Python, depending on the type of input and the needs of the program.&nbsp;Some of the more common techniques include:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Input validation using functions<\/h4>\n\n\n\n<p>We can create functions that check if a user&#8217;s input is valid or not.&nbsp;For example, to validate an integer input, we can create a function that checks if the number is a positive integer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def is_positive_integer(x):\n    return x &gt; 0\n\nnumber = int(input(\"Enter an integer: \"))\nif is_positive_integer(number):\n    print(f\"{number} is a positive integer!\")\nelse:\n    print(f\"{number} is not a positive integer!\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Input validation using regular expressions<\/h4>\n\n\n\n<p>Regular expressions are a powerful tool for validating input in Python.&nbsp;In this way, you can use a regular expression to check whether a data entry meets a specific pattern.&nbsp;For example, to validate a string input that contains only letters and numbers, we can use the regular expression&nbsp;&nbsp;<code><strong>^[a-zA-Z0-9]+$<\/strong><\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>input_1 = input(\"Please enter a valid string: \")\nif re.match(r\"^&#091;a-zA-Z0-9]+$\", input_1 ):\n    print(\"Entry is valid!\")\nelse:\n    print(\"Entry is not valid!\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Input validation using the module&nbsp;<code>bool<\/code><\/h4>\n\n\n\n<p>The module&nbsp;&nbsp;<code>bool<\/code>&nbsp;includes functions that can be used to validate input in Python.&nbsp;For example, the function&nbsp;&nbsp;<code>bool()<\/code>&nbsp;can be used to check whether an input is a valid string or not:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>input_2 = input(\"Please enter a valid string: \")\nif bool(input_2 ):\n    print(\"Entry is valid!\")\nelse:\n    print(\"Entry is not valid!\")<\/code><\/pre>\n\n\n\n<p>In addition, the module&nbsp;&nbsp;<code>bool<\/code>&nbsp;also includes the function&nbsp;&nbsp;<code><strong>not_<\/strong><\/code>, which is useful for validating whether an input is false.&nbsp;For example, if you want to validate whether a user has entered an integer, you can check whether the function&#8217;s result&nbsp;&nbsp;<code>int()<\/code>&nbsp;is false:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>number = int(input(\"Enter an integer: \"))\nif not int(number):\n    print(\"This is not a whole number!\")\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Input validation using the module&nbsp;<code>json<\/code><\/h4>\n\n\n\n<p>The module&nbsp;&nbsp;<code>json<\/code>&nbsp;includes functions that can be used to validate input data in JSON format.&nbsp;For example, you can use the function&nbsp;&nbsp;<code>json.loads()<\/code>&nbsp;to check if an input is a valid JSON object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json_string = input(\"Please enter a valid JSON string: \")\nif json.loads(json_string):\n    print(\"Entry is valid!\")\nelse:\n    print(\"Entry is not valid!\")<\/code><\/pre>\n\n\n\n<p>In summary, there are many ways to validate input in Python, and which technique is best for you depends on the type of input and the needs of the program.&nbsp;However, regardless of the technique chosen, it is important to ensure that the program receives valid and readable input data to avoid problems with the program&#8217;s operation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Accessing_input_value_in_a_dictionary_in_Python\"><\/span>Accessing input value in a dictionary in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In Python, it is possible to store user input values \u200b\u200bin a dictionary.&nbsp;This can be useful in situations where we need to store a series of input values \u200b\u200bin an organized format.<\/p>\n\n\n\n<p>To access the input value of a dictionary, we make use of the syntax&nbsp;&nbsp;<code>dictionary[key]<\/code>, where&nbsp;&nbsp;<code>chave<\/code>&nbsp;is the key corresponding to the desired input value.&nbsp;For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>words= {}\nwords&#091;\"sentence1\"] = input(\"type a sentence: \")\nwords&#091;\"sentence2\"] = input(\"type another sentence: \")\n\nprint(\"The sentence entered is:\", palavras&#091;\"sentence1\"])\nprint(\"The sentence entered is:\", palavras&#091;\"sentence2\"])<\/code><\/pre>\n\n\n\n<p>In this example, we are creating an empty dictionary called&nbsp;&nbsp;<code>palavras<\/code>.&nbsp;Next we are adding two keys&nbsp;&nbsp;<code>sentence1<\/code>&nbsp;and&nbsp;&nbsp;<code>sentence2<\/code>&nbsp;with the user input values.&nbsp;Next, we&#8217;re accessing the&nbsp;&nbsp;<code>sentence1<\/code>&nbsp;e&nbsp; key values&nbsp;<code>sentence2<\/code>&nbsp;\u200b\u200band displaying them on the screen.<\/p>\n\n\n\n<p>Also, you can access an input value directly from the dictionary without assigning it to a variable.&nbsp;In this example, we are directly accessing the user input values \u200b\u200bdirectly from the dictionary&nbsp;&nbsp;<code>palavras<\/code>, see:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>palavras = {}\npalavras&#091;\"sentence1\"] = input(\"type a sentence: \")\npalavras&#091;\"sentence2\"] = input(\"type another sentence: \")\n\nprint(\"The sentence entered is:\", palavras&#091;\"sentence1\"])\nprint(\"The sentence entered is:\", palavras&#091;\"sentence2\"])<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Usage_examples_for_simple_programs\"><\/span>Usage examples for simple programs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are many ways to use function&nbsp;&nbsp;<code>input<\/code>&nbsp;in Python to collect user data and use that data in a program.&nbsp;So, here are some examples:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Collect an integer from the user:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>number = input(\"Enter an integer: \")\nprint(\"The number you entered is\", number)<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>Collect a string from the user:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>text = input(\"Enter an string: \")\nprint(\"The string you entered is\", text)<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>Collect two strings from the user and concatenate them:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>name = input(\"type your name: \")\nsurname = input(\"enter your last name: \")\nprint(\"Your first and last name are\", name + \" \" + surname)<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li>Collect an integer and display a message if that number is even or odd:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>number = input(\"Enter an integer: \")\nif number % 2 == 0:\n    print(\"The number you entered is even\")\nelse:\n    print(\"The number you entered is odd\")<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li>Collect a string and loop through all the letters and add a comma after the first letter of each word:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>text = input(\"type a string: \")\nresponse = \"\"\nfor letter in text:\n    if letter.isalpha():\n        response += letter + \".\"\n    else:\n        response += letter\nprint(\"The string with the first letters of each word and a comma after them is: \", response)<\/code><\/pre>\n\n\n\n<p>These examples are just a small sample of how&nbsp;&nbsp;<code>input<\/code>&nbsp;can be used in conjunction with other Python functions, such as&nbsp;&nbsp;<code><a href=\"https:\/\/www.copahost.com\/blog\/for-python\/\">for<\/a><\/code>,&nbsp;&nbsp;<code><a href=\"https:\/\/www.copahost.com\/blog\/len-python\/\">len<\/a><\/code>,&nbsp;&nbsp;<code>if-else<\/code>,&nbsp;&nbsp;<code><a href=\"https:\/\/www.copahost.com\/blog\/while-python\/\">while<\/a><\/code>, to collect user data and do some operations with that data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input_types_in_Python\"><\/span>Input types in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python provides several types of input to programs, including:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>By keyboard<\/strong>&nbsp;: With the &#8216;input()&#8217; function we can use it to collect data from the user through the keyboard.<\/li>\n\n\n\n<li><strong>File<\/strong>&nbsp;: Python lets you read data from files, such as text and numbers, and use that data in programs.<\/li>\n\n\n\n<li><strong>URL<\/strong>&nbsp;: We can use it to read data from external sources, such as URLs, and use that information in programs.<\/li>\n\n\n\n<li><strong>Streams<\/strong>&nbsp;: Python also lets you read data from streamed input sources, such as serial input devices, and use that information in programs.<\/li>\n\n\n\n<li><strong>Command line input<\/strong>&nbsp;: Python allows you to read command line data, such as command line arguments passed to the program.<\/li>\n\n\n\n<li><strong>Input of a function<\/strong>&nbsp;: Python allows a function to return input data as arguments.<\/li>\n<\/ol>\n\n\n\n<p>So these are some of the input types available in Python, and each of them has its own advantages and specific uses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advanced_input_techniques_in_Python\"><\/span>Advanced input techniques in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are several advanced Python input techniques that can be useful in different situations.&nbsp;Here are some of those techniques:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Lecture:<\/strong>&nbsp;We can use this technique to read data from a file input source, user-written input, or data from an API.&nbsp;<code>csv<\/code>&nbsp;Python&nbsp;module&nbsp; is useful to read data from CSV file.&nbsp;The module&nbsp;&nbsp;<code>input<\/code>&nbsp;can also be used to read user input.<\/li>\n\n\n\n<li><strong>Entry:<\/strong>&nbsp;We can use this technique to insert data into a table or database.&nbsp;The&nbsp;&nbsp;<code>sqlite3<\/code>&nbsp;Python module is useful for inserting data into an SQLite database.&nbsp;The module&nbsp;&nbsp;<code>psycopg2<\/code>&nbsp;is useful for inserting data into a PostgreSQL database.<\/li>\n\n\n\n<li><strong>Extract:<\/strong>&nbsp;We can use this technique to extract information from a file or data from an API.&nbsp;The&nbsp;&nbsp;<code>pandas<\/code>&nbsp;Python module is useful for extracting information from a CSV file.&nbsp;The module&nbsp;&nbsp;<code>requests<\/code>&nbsp;can be used to make HTTP requests and extract information from an API.<\/li>\n\n\n\n<li><strong>Analyze:<\/strong>&nbsp;We can use this technique to analyze data.&nbsp;The&nbsp;&nbsp;<code>pandas<\/code>&nbsp;Python module is useful for performing data analysis operations.&nbsp;The module&nbsp;&nbsp;<code>numpy<\/code>&nbsp;is useful for performing mathematical calculations on vectors and matrices.<\/li>\n\n\n\n<li><strong>Sort:<\/strong>&nbsp;We can use this technique to sort data.&nbsp;The&nbsp;&nbsp;<code>pandas<\/code>&nbsp;Python module is useful for sorting data based on one or more columns.<\/li>\n\n\n\n<li><strong>Filter:<\/strong>&nbsp;We can use this technique to filter data.&nbsp;The&nbsp;&nbsp;<code>pandas<\/code>&nbsp;Python module is useful for filtering data based on one or more columns.<\/li>\n\n\n\n<li><strong>Join:<\/strong>&nbsp;We use the&nbsp;&nbsp;<code>pandas<\/code>&nbsp;Python module that is useful for joining sets of data based on one or more columns.<\/li>\n<\/ol>\n\n\n\n<p>These are just some of the advanced Python input techniques.&nbsp;Each technique has its own advantages and disadvantages, and choosing the right technique depends on the specific dataset and problem at hand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"mportant_considerations_when_using_input_in_Python_programs\"><\/span>mportant considerations when using input in Python programs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When using function&nbsp;&nbsp;<code>input()<\/code>&nbsp;in Python programs, it is important to consider some important issues to ensure that the code works correctly and is secure.&nbsp;Here are some of those considerations:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Entry validation<\/h4>\n\n\n\n<p>In this regard, it is important to validate user input to ensure that it is of the expected type and format.&nbsp;In this way, we can use regular expressions or checking the data type.&nbsp;For example, if we expect the user to enter an integer, you can check if the input is an integer using the&nbsp;&nbsp;<code>int()<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Length limitation<\/h4>\n\n\n\n<p>If you&#8217;re asking the user to enter a string, it&#8217;s important to limit the length of the string to avoid buffer overflow.&nbsp;This way, you can use the function&nbsp;&nbsp;<code>len()<\/code>&nbsp;to get the length of the string and check if it is less than a specific threshold.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. Separation of input and output<\/h4>\n\n\n\n<p>It is important to separate user input from program output so that the user can interact with the program clearly.&nbsp;You can do this by creating a separate function for the input and another function for the output.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Security<\/h4>\n\n\n\n<p>It is important to prevent the user from sending malicious code or explanations to the program.&nbsp;Therefore, you can do this using techniques such as input validation and length limiting.&nbsp;It is also important to avoid executing user code, for example by avoiding the use of functions like&nbsp;&nbsp;<code>eval()<\/code>&nbsp;and&nbsp;&nbsp;<code>exec()<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">5. Typo error<\/h4>\n\n\n\n<p>It is important to deal with typos such as typing an invalid number or an empty string.&nbsp;Thus, this can be done using an exception such as&nbsp;&nbsp;<code>ValueError<\/code>, to catch the error and display an error message to the user.<\/p>\n\n\n\n<p>As such, when using function&nbsp;&nbsp;<code>input()<\/code>&nbsp;in Python programs, it is important to consider issues of input validation, length limitation, separation of input and output, security, and typos to ensure that the code works correctly and is safe.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In conclusion, Python input is a fundamental skill for any Python developer.&nbsp;The function&nbsp;&nbsp;<code>input()<\/code>&nbsp;is a powerful tool for collecting data from user input, but it&#8217;s important to consider input validation issues, length limitation, input-output separation, security, and typos to ensure that the code works correctly and is safe.&nbsp;With a good understanding of how input works in Python, you can create more efficient and robust programs to handle user input.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inputting data is a fundamental part of any program, and the input function in Python provides an easy way to get input from the user . Thus, this function allows the programmer to ask the user to enter an input, which can be a string , an integer number, decimal or a string with numerical [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":3620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[174],"tags":[],"class_list":["post-3584","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Input python: How to validate and manipulate user data - Copahost<\/title>\n<meta name=\"description\" content=\"Learn how to use the &#039;input()&#039; function in Python to get user data. Collect different types of input, validate and manipulate data.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.copahost.com\/blog\/input-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Input python: How to validate and manipulate user data - Copahost\" \/>\n<meta property=\"og:description\" content=\"Learn how to use the &#039;input()&#039; function in Python to get user data. Collect different types of input, validate and manipulate data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.copahost.com\/blog\/input-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Copahost\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-11T15:40:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-11T15:40:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Schenia T\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Schenia T\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/\"},\"author\":{\"name\":\"Schenia T\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f\"},\"headline\":\"Input python: How to validate and manipulate user data\",\"datePublished\":\"2023-08-11T15:40:41+00:00\",\"dateModified\":\"2023-08-11T15:40:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/\"},\"wordCount\":1892,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.copahost.com\/blog\/input-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/\",\"url\":\"https:\/\/www.copahost.com\/blog\/input-python\/\",\"name\":\"Input python: How to validate and manipulate user data - Copahost\",\"isPartOf\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png\",\"datePublished\":\"2023-08-11T15:40:41+00:00\",\"dateModified\":\"2023-08-11T15:40:44+00:00\",\"description\":\"Learn how to use the 'input()' function in Python to get user data. Collect different types of input, validate and manipulate data.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.copahost.com\/blog\/input-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage\",\"url\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png\",\"contentUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png\",\"width\":1080,\"height\":1080,\"caption\":\"input python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.copahost.com\/blog\/input-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.copahost.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Input python: How to validate and manipulate user data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#website\",\"url\":\"https:\/\/www.copahost.com\/blog\/\",\"name\":\"Copahost\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.copahost.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\",\"name\":\"Copahost\",\"url\":\"https:\/\/www.copahost.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png\",\"contentUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png\",\"width\":223,\"height\":40,\"caption\":\"Copahost\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f\",\"name\":\"Schenia T\",\"description\":\"Data scientist, passionate about technology tools and games. Undergraduate student in Statistics at UFPB. Her hobby is binge-watching series, enjoying good music working or cooking, going to the movies and learning new things!\",\"url\":\"https:\/\/www.copahost.com\/blog\/author\/schenia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Input python: How to validate and manipulate user data - Copahost","description":"Learn how to use the 'input()' function in Python to get user data. Collect different types of input, validate and manipulate data.","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:\/\/www.copahost.com\/blog\/input-python\/","og_locale":"en_US","og_type":"article","og_title":"Input python: How to validate and manipulate user data - Copahost","og_description":"Learn how to use the 'input()' function in Python to get user data. Collect different types of input, validate and manipulate data.","og_url":"https:\/\/www.copahost.com\/blog\/input-python\/","og_site_name":"Copahost","article_published_time":"2023-08-11T15:40:41+00:00","article_modified_time":"2023-08-11T15:40:44+00:00","og_image":[{"width":1080,"height":1080,"url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png","type":"image\/png"}],"author":"Schenia T","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Schenia T","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.copahost.com\/blog\/input-python\/#article","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/input-python\/"},"author":{"name":"Schenia T","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f"},"headline":"Input python: How to validate and manipulate user data","datePublished":"2023-08-11T15:40:41+00:00","dateModified":"2023-08-11T15:40:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/input-python\/"},"wordCount":1892,"commentCount":0,"publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.copahost.com\/blog\/input-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.copahost.com\/blog\/input-python\/","url":"https:\/\/www.copahost.com\/blog\/input-python\/","name":"Input python: How to validate and manipulate user data - Copahost","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png","datePublished":"2023-08-11T15:40:41+00:00","dateModified":"2023-08-11T15:40:44+00:00","description":"Learn how to use the 'input()' function in Python to get user data. Collect different types of input, validate and manipulate data.","breadcrumb":{"@id":"https:\/\/www.copahost.com\/blog\/input-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.copahost.com\/blog\/input-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/input-python\/#primaryimage","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/08\/input-python.png","width":1080,"height":1080,"caption":"input python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.copahost.com\/blog\/input-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.copahost.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Input python: How to validate and manipulate user data"}]},{"@type":"WebSite","@id":"https:\/\/www.copahost.com\/blog\/#website","url":"https:\/\/www.copahost.com\/blog\/","name":"Copahost","description":"","publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.copahost.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.copahost.com\/blog\/#organization","name":"Copahost","url":"https:\/\/www.copahost.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","width":223,"height":40,"caption":"Copahost"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f","name":"Schenia T","description":"Data scientist, passionate about technology tools and games. Undergraduate student in Statistics at UFPB. Her hobby is binge-watching series, enjoying good music working or cooking, going to the movies and learning new things!","url":"https:\/\/www.copahost.com\/blog\/author\/schenia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/comments?post=3584"}],"version-history":[{"count":11,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3584\/revisions"}],"predecessor-version":[{"id":3634,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3584\/revisions\/3634"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media\/3620"}],"wp:attachment":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media?parent=3584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/categories?post=3584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/tags?post=3584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}