{"id":20412,"date":"2022-01-08T09:08:16","date_gmt":"2022-01-08T03:38:16","guid":{"rendered":"https:\/\/hermagic.com\/?p=20412"},"modified":"2023-03-24T17:59:03","modified_gmt":"2023-03-24T12:29:03","slug":"a-brief-introduction-to-python-function","status":"publish","type":"post","link":"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/","title":{"rendered":"Uma Breve Introdu\u00e7\u00e3o \u00e0 Fun\u00e7\u00e3o Python"},"content":{"rendered":"<div id=\"attachment_20414\" style=\"width: 910px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-20414\" class=\"size-full wp-image-20414 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Python Function\" width=\"900\" height=\"400\" sizes=\"(max-width: 900px) 100vw, 900px\" data-src=\"https:\/\/hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function.webp 900w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function-300x133.webp 300w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function-600x267.webp 600w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function-150x67.webp 150w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function-768x341.webp 768w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/03\/Python-Function-18x8.webp 18w\"><p id=\"caption-attachment-20414\" class=\"wp-caption-text\">Fun\u00e7\u00e3o Python | Hermagic<\/p><\/div>\n<p><span style=\"font-weight: 400;\">Em Python, fun\u00e7\u00f5es s\u00e3o usadas para dividir programas maiores em partes menores e mais gerenci\u00e1veis. Eles tamb\u00e9m ajudam na reutiliza\u00e7\u00e3o de c\u00f3digo, o que significa que um bloco de c\u00f3digo pode ser usado v\u00e1rias vezes ao longo do programa sem ter que reescrev\u00ea-lo a cada vez. As fun\u00e7\u00f5es do Python podem ser chamadas em qualquer ponto do programa e tamb\u00e9m podem retornar valores, tornando-as ferramentas vers\u00e1teis para resolver problemas complexos de programa\u00e7\u00e3o. Continue lendo para saber mais sobre as fun\u00e7\u00f5es em python e a fun\u00e7\u00e3o lambda em python.<\/span><\/p>\n\t\t<div class=\"web-stories-list alignnone has-archive-link is-view-type-circles is-style-default is-carousel\" data-id=\"1\">\n\t\t\t<div class=\"web-stories-list__inner-wrapper carousel-1\" style=\"--ws-circle-size:100px\">\n\t\t\t\t\t\t\t\t\t<div class=\"web-stories-list__carousel circles\" data-id=\"carousel-1\">\n\t\t\t\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/you-will-absolutely-love-these-designer-clothing-for-men-in-2022\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"You Will Absolutely Love These Designer Clothing For Men In 2022\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/10\/cropped-1-4.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/10\/cropped-1-4.webp 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/10\/cropped-1-4-225x300.webp 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/10\/cropped-1-4-432x576.webp 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/10\/cropped-1-4-113x150.webp 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/10\/cropped-1-4-150x200.webp 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/workout-in-style-with-the-top-nike-headbands-in-2022\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Workout In Style With The Top Nike Headbands In 2022\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Nike-Womens-Fury-Headband-3.0.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Nike-Womens-Fury-Headband-3.0.webp 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Nike-Womens-Fury-Headband-3.0-225x300.webp 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Nike-Womens-Fury-Headband-3.0-432x576.webp 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Nike-Womens-Fury-Headband-3.0-113x150.webp 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Nike-Womens-Fury-Headband-3.0-150x200.webp 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/wear-these-slips-control-pants-for-tummy-for-a-perfect-fit-of-your-outfit\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Wear These Slips &#038; Control Pants For Tummy For A Perfect Fit Of Your Outfit\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Control-Pants-for-Tummy.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Control-Pants-for-Tummy.webp 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Control-Pants-for-Tummy-225x300.webp 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Control-Pants-for-Tummy-432x576.webp 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Control-Pants-for-Tummy-113x150.webp 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Control-Pants-for-Tummy-150x200.webp 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/wear-these-best-chino-pants-for-men-for-a-formal-look\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Wear These Best Chino Pants For Men For A Formal Look\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-chino-pants-for-men-1.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-chino-pants-for-men-1.webp 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-chino-pants-for-men-1-225x300.webp 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-chino-pants-for-men-1-432x576.webp 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-chino-pants-for-men-1-113x150.webp 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-chino-pants-for-men-1-150x200.webp 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/best-shampoos-and-conditioners\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Ulta Beauty Disseminating Best Shampoos And Conditioners\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Best-Shampoos-And-Conditioners-.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Best-Shampoos-And-Conditioners-.webp 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Best-Shampoos-And-Conditioners--225x300.webp 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Best-Shampoos-And-Conditioners--432x576.webp 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Best-Shampoos-And-Conditioners--113x150.webp 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2023\/01\/cropped-Best-Shampoos-And-Conditioners--150x200.webp 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/types-of-womens-boots-to-invest-in-2022\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Types Of Womens Boots To Invest In 2022\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Womens-Boots.jpg\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Womens-Boots.jpg 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Womens-Boots-225x300.jpg 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Womens-Boots-432x576.jpg 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Womens-Boots-113x150.jpg 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Womens-Boots-150x200.jpg 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/trending-backpacks-for-women-for-every-occasion\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Trending Backpacks For Women For Every Occasion\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Untitled-design-2.webp\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Untitled-design-2.webp 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Untitled-design-2-225x300.webp 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Untitled-design-2-432x576.webp 432w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Untitled-design-2-113x150.webp 113w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/12\/cropped-Untitled-design-2-150x200.webp 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"web-stories-list__story\">\n\t\t\t\t\t\t\t<div class=\"web-stories-list__story-poster\">\n\t\t\t\t<a href=\"https:\/\/test2.hermagic.com\/pt\/web-stories\/top-yoga-accessories\/\" >\n\t\t\t\t\t<img src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"Top Yoga Accessories\" width=\"185\" height=\"308\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" loading=\"lazy\" decoding=\"async\" class=\"lazyload\" data-src=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/09\/cropped-1st.jpg\" data-srcset=\"https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/09\/cropped-1st.jpg 640w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/09\/cropped-1st-225x300.jpg 225w, https:\/\/test2.hermagic.com\/wp-content\/uploads\/2022\/09\/cropped-1st-150x200.jpg 150w\">\n\t\t\t\t<\/a>\n\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<div tabindex=\"0\" aria-label=\"Voltar\" class=\"glider-prev\"><\/div>\n\t\t\t\t\t<div tabindex=\"0\" aria-label=\"Avan\u00e7ar\" class=\"glider-next\"><\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_46 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\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"ez-toc-toggle-icon-1\"><label for=\"item-69dd42324d5af\" aria-label=\"Table of Content\"><span style=\"display: flex;align-items: center;width: 35px;height: 30px;justify-content: center;direction:ltr;\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/label><input  type=\"checkbox\" id=\"item-69dd42324d5af\"><\/a><\/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:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Defining_a_Python_Function\" title=\"Definindo uma Fun\u00e7\u00e3o Python\">Definindo uma Fun\u00e7\u00e3o Python<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Function_parameters_and_arguments\" title=\"Par\u00e2metros e argumentos da fun\u00e7\u00e3o\">Par\u00e2metros e argumentos da fun\u00e7\u00e3o<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Calling_a_Python_function\" title=\"Chamando uma fun\u00e7\u00e3o Python\">Chamando uma fun\u00e7\u00e3o Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Returning_values\" title=\"Retornando valores\">Retornando valores<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#What_is_the_built-in_python_function\" title=\"Qual \u00e9 a fun\u00e7\u00e3o interna do python?\">Qual \u00e9 a fun\u00e7\u00e3o interna do 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:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Why_are_built-in_functions_important\" title=\"Por que as fun\u00e7\u00f5es integradas s\u00e3o importantes?\">Por que as fun\u00e7\u00f5es integradas s\u00e3o importantes?<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Save_time_and_effort\" title=\"Economize tempo e esfor\u00e7o\">Economize tempo e esfor\u00e7o<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Optimization\" title=\"Otimiza\u00e7\u00e3o\">Otimiza\u00e7\u00e3o<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Easy_to_understand\" title=\"F\u00e1cil de entender\">F\u00e1cil de entender<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#Conclusion\" title=\"Conclus\u00e3o\">Conclus\u00e3o<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/test2.hermagic.com\/pt\/a-brief-introduction-to-python-function\/#FAQs\" title=\"perguntas frequentes\">perguntas frequentes<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Defining_a_Python_Function\"><\/span><span style=\"font-weight: 400;\">Definindo uma Fun\u00e7\u00e3o Python<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Em Python, uma fun\u00e7\u00e3o \u00e9 definida usando a palavra-chave \u201cdef\u201d seguida do nome da fun\u00e7\u00e3o e um conjunto de par\u00eanteses. Os par\u00eanteses podem conter par\u00e2metros opcionais que a fun\u00e7\u00e3o usa para executar sua tarefa. O corpo da fun\u00e7\u00e3o \u00e9 recuado e pode conter qualquer <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">n\u00famero de declara\u00e7\u00f5es<\/span><\/a><span style=\"font-weight: 400;\">, incluindo instru\u00e7\u00f5es condicionais, loops e outras fun\u00e7\u00f5es.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aqui est\u00e1 um exemplo de uma fun\u00e7\u00e3o Python simples que imprime uma mensagem:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">def print_message():<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0print(\u201cOl\u00e1, mundo!\u201d)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Neste exemplo, definimos uma fun\u00e7\u00e3o chamada <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">\u201cimprimir_mensagem\u201d<\/span><\/a><span style=\"font-weight: 400;\"> que n\u00e3o aceita nenhum argumento e simplesmente imprime a mensagem \u201cHello, world!\u201d quando chamado.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Function_parameters_and_arguments\"><\/span><span style=\"font-weight: 400;\">Par\u00e2metros e argumentos da fun\u00e7\u00e3o<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">As fun\u00e7\u00f5es do Python tamb\u00e9m podem receber um ou mais par\u00e2metros, que s\u00e3o espa\u00e7os reservados para os dados de que a fun\u00e7\u00e3o precisa para executar sua tarefa. Quando uma fun\u00e7\u00e3o \u00e9 chamada, os valores que s\u00e3o passados para os par\u00e2metros s\u00e3o chamados de argumentos. Par\u00e2metros e argumentos podem ser de qualquer tipo de dados, incluindo strings, inteiros, flutuantes e muito mais.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aqui est\u00e1 um exemplo de uma fun\u00e7\u00e3o Python que recebe dois par\u00e2metros e retorna sua soma:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">def add_numbers(x, y):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0retornar x + y<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Neste exemplo, definimos uma fun\u00e7\u00e3o chamada \u201cadd_numbers\u201d que recebe dois par\u00e2metros, \u201cx\u201d e \u201cy\u201d. O corpo da fun\u00e7\u00e3o retorna a soma desses dois par\u00e2metros.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Calling_a_Python_function\"><\/span><span style=\"font-weight: 400;\">Chamando uma fun\u00e7\u00e3o Python<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Para chamar uma fun\u00e7\u00e3o Python, simplesmente usamos o nome da fun\u00e7\u00e3o seguido de par\u00eanteses. Se a fun\u00e7\u00e3o receber argumentos, n\u00f3s os passamos dentro dos par\u00eanteses.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aqui est\u00e1 um exemplo de chamada da fun\u00e7\u00e3o \u201cprint_message\u201d que definimos anteriormente:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">print_message()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ao chamarmos esta fun\u00e7\u00e3o, ela imprimir\u00e1 a mensagem \u201cHello, world!\u201d para o console.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aqui est\u00e1 um exemplo de como chamar a fun\u00e7\u00e3o \u201cadd_numbers\u201d com argumentos:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">resultado = add_numbers(3, 5)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">imprimir(resultado)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Neste exemplo, chamamos a fun\u00e7\u00e3o \u201cadd_numbers\u201d com os argumentos 3 e 5. A fun\u00e7\u00e3o retornou sua soma, que armazenamos em uma vari\u00e1vel chamada \u201cresult\u201d. Nosso pr\u00f3ximo passo foi enviar o n\u00famero de \u201cresultado\u201d para o console.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Returning_values\"><\/span><span style=\"font-weight: 400;\">Retornando valores<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">As fun\u00e7\u00f5es do Python tamb\u00e9m podem retornar valores usando a palavra-chave \u201creturn\u201d. Quando uma fun\u00e7\u00e3o retorna um valor, ela pode ser atribu\u00edda a uma vari\u00e1vel ou usada de qualquer outra forma que um valor desse tipo de dados possa ser usado.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aqui est\u00e1 um exemplo de uma fun\u00e7\u00e3o Python que retorna o quadrado de um n\u00famero:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">def quadrado(x):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0retornar x ** 2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Neste exemplo, definimos um <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">fun\u00e7\u00e3o chamada \u201cquadrado\u201d<\/span><\/a><span style=\"font-weight: 400;\"> que leva um par\u00e2metro, \u201cx\u201d. O corpo da fun\u00e7\u00e3o retorna o quadrado de \u201cx\u201d.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Podemos chamar esta fun\u00e7\u00e3o e atribuir seu valor de retorno a uma vari\u00e1vel como esta:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">resultado = quadrado(4)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">imprimir(resultado)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Neste exemplo, chamamos a fun\u00e7\u00e3o \u201csquare\u201d com o argumento 4. A fun\u00e7\u00e3o retornou o quadrado de 4 (que \u00e9 16), que armazenamos em uma vari\u00e1vel chamada \u201cresult\u201d. Em seguida, enviamos para o console o n\u00famero que foi armazenado na vari\u00e1vel \u201cresultado\u201d.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_is_the_built-in_python_function\"><\/span><span style=\"font-weight: 400;\">Qual \u00e9 a fun\u00e7\u00e3o interna do python?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Em Python, <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">fun\u00e7\u00f5es embutidas<\/span><\/a><span style=\"font-weight: 400;\"> s\u00e3o fun\u00e7\u00f5es que est\u00e3o dispon\u00edveis na biblioteca padr\u00e3o da linguagem. Essas fun\u00e7\u00f5es s\u00e3o predefinidas e podem ser usadas diretamente em um programa sem exigir instru\u00e7\u00f5es de importa\u00e7\u00e3o adicionais ou instala\u00e7\u00f5es de biblioteca. As fun\u00e7\u00f5es integradas s\u00e3o projetadas para fornecer <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">funcionalidades comumente usadas<\/span><\/a><span style=\"font-weight: 400;\"> que s\u00e3o necess\u00e1rios na maioria dos programas. Essas fun\u00e7\u00f5es s\u00e3o otimizadas para desempenho e s\u00e3o implementadas em C ou no pr\u00f3prio Python, tornando-as <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">r\u00e1pido e eficiente<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_are_built-in_functions_important\"><\/span><span style=\"font-weight: 400;\">Por que as fun\u00e7\u00f5es integradas s\u00e3o importantes?<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">As fun\u00e7\u00f5es incorporadas s\u00e3o importantes na programa\u00e7\u00e3o Python por v\u00e1rios motivos.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Save_time_and_effort\"><\/span><span style=\"font-weight: 400;\">Economize tempo e esfor\u00e7o<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a0Em primeiro lugar, eles <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">economizar tempo e esfor\u00e7o<\/span><\/a><span style=\"font-weight: 400;\"> fornecendo funcionalidade predefinida, que pode ser usada diretamente em um programa sem qualquer declara\u00e7\u00e3o ou defini\u00e7\u00e3o pr\u00e9via.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Optimization\"><\/span><span style=\"font-weight: 400;\">Otimiza\u00e7\u00e3o<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">As fun\u00e7\u00f5es incorporadas s\u00e3o<\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\"> otimizado para desempenho<\/span><\/a><span style=\"font-weight: 400;\">, o que significa que eles s\u00e3o executados mais rapidamente do que as fun\u00e7\u00f5es definidas pelo usu\u00e1rio. Isso ocorre porque as fun\u00e7\u00f5es internas s\u00e3o implementadas em C ou no pr\u00f3prio Python, tornando-as mais eficientes.<\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Easy_to_understand\"><\/span><span style=\"font-weight: 400;\">F\u00e1cil de entender<\/span><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">As fun\u00e7\u00f5es incorporadas fornecem uma maneira padronizada de executar tarefas comuns, o que torna o c\u00f3digo mais leg\u00edvel e f\u00e1cil de entender. Isso ocorre porque as fun\u00e7\u00f5es internas t\u00eam nomes e sintaxe consistentes, o que as torna <\/span><a href=\"https:\/\/hermagic.com\/z0lt\" target=\"_blank\" rel=\"nofollow noopener sponsored\"><span style=\"font-weight: 400;\">mais f\u00e1cil de reconhecer e usar<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><span style=\"font-weight: 400;\">Conclus\u00e3o<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\"><a href=\"https:\/\/en.wikipedia.org\/wiki\/Python_(programming_language)\" target=\"_blank\" rel=\"noopener\">fun\u00e7\u00f5es Python<\/a> oferecem muitos benef\u00edcios aos programadores. Eles podem ser usados para dividir grandes programas em partes menores e mais gerenci\u00e1veis, facilitando a manuten\u00e7\u00e3o e atualiza\u00e7\u00e3o do c\u00f3digo. Al\u00e9m disso, as fun\u00e7\u00f5es permitem a reutiliza\u00e7\u00e3o de c\u00f3digo, o que pode economizar uma quantidade significativa de tempo e esfor\u00e7o a longo prazo. Ao projetar fun\u00e7\u00f5es, \u00e9 importante considerar fatores como par\u00e2metros de entrada, valores de sa\u00edda e tratamento de erros para garantir que sejam robustos e confi\u00e1veis. Testar as fun\u00e7\u00f5es minuciosamente tamb\u00e9m \u00e9 fundamental para garantir que elas funcionem conforme o esperado e produzam resultados precisos. Para mais informa\u00e7\u00f5es visite <\/span><span style=\"font-weight: 400;\"><a href=\"https:\/\/hermagic.com\/\" target=\"_blank\" rel=\"noopener\">Hermagic<\/a>.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"FAQs\"><\/span><span style=\"font-weight: 400;\">PERGUNTAS FREQUENTES&#039;<\/span><span style=\"font-weight: 400;\">s<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"su-accordion su-u-trim\"><div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Os quatro tipos de fun\u00e7\u00e3o do Python?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<p>Fun\u00e7\u00f5es integradas: s\u00e3o fun\u00e7\u00f5es incorporadas \u00e0 linguagem Python e est\u00e3o sempre dispon\u00edveis para uso. Exemplos incluem print(), len(), min(), max(), etc.<br \/>\nFun\u00e7\u00f5es definidas pelo usu\u00e1rio: s\u00e3o fun\u00e7\u00f5es definidas pelo usu\u00e1rio e podem ser usadas para executar uma tarefa espec\u00edfica.<br \/>\nFun\u00e7\u00f5es Lambda: s\u00e3o fun\u00e7\u00f5es an\u00f4nimas definidas sem um nome. Eles geralmente s\u00e3o usados para situa\u00e7\u00f5es em que uma fun\u00e7\u00e3o \u00e9 usada apenas uma vez.<br \/>\nFun\u00e7\u00f5es Recursivas: S\u00e3o fun\u00e7\u00f5es que chamam a si mesmas, o que lhes permite repetir uma tarefa at\u00e9 que uma determinada condi\u00e7\u00e3o seja atendida. Exemplos incluem fatoriais e n\u00fameros de Fibonacci.<\/div><\/div> <div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>O que \u00e9 uma fun\u00e7\u00e3o em Python?<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">Em Python, uma fun\u00e7\u00e3o \u00e9 uma se\u00e7\u00e3o discreta de c\u00f3digo que pode ser chamada repetidamente para realizar a mesma tarefa. Voc\u00ea pode melhorar a modularidade e reutiliza\u00e7\u00e3o de seu programa usando fun\u00e7\u00f5es. Embora o Python inclua muitos m\u00e9todos \u00fateis por padr\u00e3o (print(), etc.), ele tamb\u00e9m permite que voc\u00ea escreva o seu pr\u00f3prio. Essas fun\u00e7\u00f5es s\u00e3o chamadas de fun\u00e7\u00f5es definidas pelo usu\u00e1rio.<\/div><\/div> <div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>D\u00ea um exemplo do que \u00e9 uma fun\u00e7\u00e3o em Python.<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">Em Python, uma fun\u00e7\u00e3o \u00e9 um bloco de c\u00f3digo que faz um determinado trabalho e fornece um resultado. As fun\u00e7\u00f5es ajudam a tornar o c\u00f3digo mais organizado e f\u00e1cil de ler.<\/p>\n<p>Um exemplo de fun\u00e7\u00e3o em Python \u00e9 o seguinte:<\/p>\n<p>def double_number(x):<\/p>\n<p>return x * 2Esta fun\u00e7\u00e3o recebe um \u00fanico argumento (x) e retorna o resultado desse argumento multiplicado por 2.<\/div><\/div><\/div>\n<p><script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"Python's four function types?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"Built-in Functions: These are functions that are built into the Python language and are always available to use. Examples include print(), len(), min(), max(), etc.\nUser-defined Functions: These are functions that are defined by the user and can be used to perform a specific task.\nLambda Functions: These are anonymous functions that are defined without a name. They are usually used for situations where a function is only used once.\nRecursive Functions: These are functions that call themselves, which allows them to repeat a task until a certain condition is met. Examples include factorials and Fibonacci numbers.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"What is a function in Python?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"In Python, a function is a discrete section of code that can be called repeatedly to carry out the same task. You can improve the modularity and reusability of your programme by using functions.\u00a0 Although Python includes many useful methods by default (print(), etc.), it also allows you to write your own. These functions are called user-defined functions.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"Give an example of what a function is in Python.\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"In Python, a function is a block of code that does a certain job and gives a result. Functions help to make code more organized and easier to read.<\/p>\n<p>An example of a function in Python is the following:<\/p>\n<p>def double_number(x):<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0return x * 2<\/p>\n<p>This function takes in a single argument (x) and returns the result of that argument multiplied by 2.\"\n    }\n  }]\n}\n<\/script><\/p>","protected":false},"excerpt":{"rendered":"<p>In Python, Functions are used to break down larger programs into smaller, more manageable pieces. They also help in code reusability, which means that a block of code can be used multiple times throughout the program without having to rewrite it each time. Python functions can be called at any point in the program, and [&hellip;]<\/p>","protected":false},"author":2,"featured_media":20413,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[851],"tags":[940],"class_list":["post-20412","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-python"],"_links":{"self":[{"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/posts\/20412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/comments?post=20412"}],"version-history":[{"count":0,"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/posts\/20412\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/media\/20413"}],"wp:attachment":[{"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/media?parent=20412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/categories?post=20412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/test2.hermagic.com\/pt\/wp-json\/wp\/v2\/tags?post=20412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}