<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Возврат нескольких значений в функциях Python - Python 3 | Data Science | Нейронные сети | AI - Искусственный Интеллект</title>
	<atom:link href="https://python.ivan-shamaev.ru/tag/%D0%B2%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82-%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85-%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9-%D0%B2-%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8/feed/" rel="self" type="application/rss+xml" />
	<link>https://python.ivan-shamaev.ru/tag/возврат-нескольких-значений-в-функци/</link>
	<description>Библиотеки обработки данных. Примеры. Строки, списки, файлы, числа, массивы. Язык программирования Python 3 - скачать</description>
	<lastBuildDate>Tue, 30 Aug 2022 07:29:04 +0000</lastBuildDate>
	<language>ru-RU</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://python.ivan-shamaev.ru/wp-content/uploads/2019/04/cropped-data_science_python3_logo-32x32.png</url>
	<title>Возврат нескольких значений в функциях Python - Python 3 | Data Science | Нейронные сети | AI - Искусственный Интеллект</title>
	<link>https://python.ivan-shamaev.ru/tag/возврат-нескольких-значений-в-функци/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Возврат нескольких значений в функциях Python</title>
		<link>https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/</link>
					<comments>https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/#respond</comments>
		
		<dc:creator><![CDATA[Шамаев Иван]]></dc:creator>
		<pubDate>Tue, 30 Aug 2022 04:49:34 +0000</pubDate>
				<category><![CDATA[Введение в Python 3]]></category>
		<category><![CDATA[Примеры скриптов (кода) Python 3]]></category>
		<category><![CDATA[return function python]]></category>
		<category><![CDATA[Возврат нескольких значений в функциях Python]]></category>
		<category><![CDATA[Функции Python 3]]></category>
		<guid isPermaLink="false">https://python.ivan-shamaev.ru/?p=1624</guid>

					<description><![CDATA[<p>В Python мы можем возвращать несколько значений из функции. Ниже приведены различные способы Использование объекта (object) Это похоже на C/C++ и Java, мы можем создать класс (в C, структуру) для хранения нескольких значений и возврата объекта класса. # A Python program to return multiple # values from a method using class class Test: def __init__(self): [&#8230;]</p>
<p>Сообщение <a href="https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/">Возврат нескольких значений в функциях Python</a> появились сначала на <a href="https://python.ivan-shamaev.ru">Python 3 | Data Science | Нейронные сети | AI - Искусственный Интеллект</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_vk" href="https://www.addtoany.com/add_to/vk?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="VK" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_email" href="https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Email" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&#038;title=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" data-a2a-url="https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/" data-a2a-title="Возврат нескольких значений в функциях Python"></a></p><p>В Python мы можем возвращать несколько значений из функции. Ниже приведены различные способы</p>
<h1>Использование объекта (object)</h1>
<p>Это похоже на C/C++ и Java, мы можем создать класс (в C, структуру) для хранения нескольких значений и возврата объекта класса.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python"># A Python program to return multiple 
# values from a method using class
class Test:
    def __init__(self):
        self.str = "string example"
        self.x = 20   
  
# This function returns an object of Test
def fun():
    return Test()
      
# Driver code to test above method
t = fun() 
print(t.str)
print(t.x)</pre>
<p><strong>Результат работы кода:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">string example
20</pre>
<h1>Использование кортежа (tuple)</h1>
<p>Кортеж представляет собой последовательность элементов, разделенных запятыми. Он создается с или без (). Кортежи неизменны.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python"># A Python program to return multiple 
# values from a method using tuple
  
# This function returns a tuple
def fun():
    str = "string&nbsp;example"
    x   = 20
    return str, x;  # Return tuple, we could also
                    # write (str, x)
  
# Driver code to test above method
str, x = fun() # Assign returned tuple
print(str)
print(x)</pre>
<p><strong>Результат работы кода:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">string&nbsp;example
20</pre>
<h1>Использование списка (list)</h1>
<p>Список похож на массив элементов, созданный с помощью квадратных скобок. Они отличаются от массивов тем, что могут содержать элементы разных типов. Списки отличаются от кортежей тем, что они изменяемы.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python"># A Python program to return multiple 
# values from a method using list
  
# This function returns a list
def fun():
    str = "string&nbsp;example"
    x = 20   
    return [str, x];  
  
# Driver code to test above method
list = fun() 
print(list)</pre>
<p><strong>Результат работы кода:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">['string&nbsp;example', 20]</pre>
<h1>Использование словаря (dictionary)</h1>
<p>Словарь похож на хэш или карту на других языках.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python"># A Python program to return multiple 
# values from a method using dictionary
  
# This function returns a dictionary
def fun():
    d = dict(); 
    d['str'] = "string&nbsp;example"
    d['x']   = 20
    return d
  
# Driver code to test above method
d = fun() 
print(d)</pre>
<p><strong>Результат работы кода:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">{'x': 20, 'str': 'string&nbsp;example'}</pre>
<h1>Использование класса данных (Data Class)</h1>
<p>В Python 3.7 и более поздних версиях класс данных можно использовать для возврата класса с автоматически добавленными уникальными методами. Модуль класса данных имеет декоратор и функции для автоматического добавления сгенерированных специальных методов, таких как __init__() и __repr__() в пользовательские классы.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python">from dataclasses import dataclass
  
@dataclass
class Book_list:
    name: str
    perunit_cost: float
    quantity_available: int = 0
          
    # function to calculate total cost    
    def total_cost(self) -&gt; float:
        return self.perunit_cost * self.quantity_available
      
book = Book_list("Introduction to programming.", 300, 3)
x = book.total_cost()
  
# print the total cost
# of the book
print(x)
  
# print book details
print(book)
  
# 900
Book_list(name='Python programming.',
          perunit_cost=200,
          quantity_available=3)</pre>
<p><strong>Результат работы кода:</strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">900
Book_list(name='Introduction to programming.', perunit_cost=300, quantity_available=3)
Book_list(name='Python programming.', perunit_cost=200, quantity_available=3)</pre>
<p><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_vk" href="https://www.addtoany.com/add_to/vk?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="VK" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_email" href="https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&amp;linkname=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" title="Email" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fpython.ivan-shamaev.ru%2Fhow-to-return-multiple-values-in-python%2F&#038;title=%D0%92%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%82%20%D0%BD%D0%B5%D1%81%D0%BA%D0%BE%D0%BB%D1%8C%D0%BA%D0%B8%D1%85%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B9%20%D0%B2%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%D1%85%20Python" data-a2a-url="https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/" data-a2a-title="Возврат нескольких значений в функциях Python"></a></p><p>Сообщение <a href="https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/">Возврат нескольких значений в функциях Python</a> появились сначала на <a href="https://python.ivan-shamaev.ru">Python 3 | Data Science | Нейронные сети | AI - Искусственный Интеллект</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://python.ivan-shamaev.ru/how-to-return-multiple-values-in-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
