<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.itcollege.ee/index.php?action=history&amp;feed=atom&amp;title=I719_Fundamentals_of_Python%2Flecture2v2</id>
	<title>I719 Fundamentals of Python/lecture2v2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.itcollege.ee/index.php?action=history&amp;feed=atom&amp;title=I719_Fundamentals_of_Python%2Flecture2v2"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=I719_Fundamentals_of_Python/lecture2v2&amp;action=history"/>
	<updated>2026-06-16T02:41:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.itcollege.ee/index.php?title=I719_Fundamentals_of_Python/lecture2v2&amp;diff=120167&amp;oldid=prev</id>
		<title>Eroman: Created page with &quot;= Lecture 2 =  Dictionaries, Importing, HTTP Requests, and Classes  == Dictionaries ==  Map keys to values  &lt;source lang=&quot;python&quot;&gt;# Make a list &gt;&gt;&gt; a = [1, 2, 3] # get element...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=I719_Fundamentals_of_Python/lecture2v2&amp;diff=120167&amp;oldid=prev"/>
		<updated>2017-04-17T10:03:14Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Lecture 2 =  Dictionaries, Importing, HTTP Requests, and Classes  == Dictionaries ==  Map keys to values  &amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;# Make a list &amp;gt;&amp;gt;&amp;gt; a = [1, 2, 3] # get element...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Lecture 2 =&lt;br /&gt;
&lt;br /&gt;
Dictionaries, Importing, HTTP Requests, and Classes&lt;br /&gt;
&lt;br /&gt;
== Dictionaries ==&lt;br /&gt;
&lt;br /&gt;
Map keys to values&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;# Make a list&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a = [1, 2, 3]&lt;br /&gt;
# get element of a list using the index of an element &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[1]&lt;br /&gt;
2&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; a[0]&lt;br /&gt;
1&lt;br /&gt;
# get character in a string using the index of a character&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; hello = &amp;quot;hello&amp;quot;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; hello[1]&lt;br /&gt;
&amp;#039;e&amp;#039;&lt;br /&gt;
# create a dictionary, with name of a programming language as a key&lt;br /&gt;
# and the year created as the value&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict = {&amp;#039;python&amp;#039;: 1991}&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict&lt;br /&gt;
{&amp;#039;python&amp;#039;: 1991}&lt;br /&gt;
# get value from a dictionary using the key&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict[&amp;#039;python&amp;#039;]&lt;br /&gt;
1991&lt;br /&gt;
# accessing a key that does not exist&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict[&amp;#039;p&amp;#039;]&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File &amp;quot;&amp;lt;input&amp;gt;&amp;quot;, line 1, in &amp;lt;module&amp;gt;&lt;br /&gt;
    example_dict[&amp;#039;p&amp;#039;]&lt;br /&gt;
KeyError: &amp;#039;p&amp;#039;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict.get(&amp;#039;python&amp;#039;)&lt;br /&gt;
1991&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict.get(&amp;#039;pythons&amp;#039;)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict.get(&amp;#039;pythons&amp;#039;, 1990)&lt;br /&gt;
1990&lt;br /&gt;
# adding a new item (key and value pair) to a dictionary&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict[&amp;#039;javascript&amp;#039;] = 1995&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; example_dict&lt;br /&gt;
{&amp;#039;javascript&amp;#039;: 1995, &amp;#039;python&amp;#039;: 1991}&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
== Example creation of dictionary ==&lt;br /&gt;
&lt;br /&gt;
Make a dictionary mapping numbers to squares&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;def map_numbers_to_squares(numbers):&lt;br /&gt;
    result = {}&lt;br /&gt;
    for number in numbers:&lt;br /&gt;
        result[number] = number ** 2&lt;br /&gt;
    return result&amp;lt;/source&amp;gt;&lt;br /&gt;
== TASK 1 ==&lt;br /&gt;
&lt;br /&gt;
Args: multiplier: a number to multiply numbers by numbers: a list of numbers&lt;br /&gt;
&lt;br /&gt;
Returns: dict of numbers, mapping each number to the number multiplied by the multiplier number is the key, the product is the value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&amp;gt;&amp;gt;&amp;gt; test_function(4, [1,2])&lt;br /&gt;
# 1*4 = 4, 2*4 = 8&lt;br /&gt;
{1: 3, 2: 8}&amp;lt;/source&amp;gt;&lt;br /&gt;
Answer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;def map_products(multiplier, numbers):&lt;br /&gt;
    result = {}&lt;br /&gt;
    for number in numbers:&lt;br /&gt;
        result[number] = number * multiplier&lt;br /&gt;
    return result&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
== Importing ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;import requests&lt;br /&gt;
import requests as r&lt;br /&gt;
from requests import get&amp;lt;/source&amp;gt;&lt;br /&gt;
== Requests library ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;pip3 install requests&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;import requests&lt;br /&gt;
&lt;br /&gt;
response = requests.get(&amp;#039;http://google.com&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
response.text  # get the response body as a string&lt;br /&gt;
&lt;br /&gt;
response.json()  # if the response is json, convert it into python native types&amp;lt;/source&amp;gt;&lt;br /&gt;
== TASK 2 ==&lt;br /&gt;
&lt;br /&gt;
Get the bitcoin price in euros, and print it.&lt;br /&gt;
&lt;br /&gt;
== Importable thing ==&lt;br /&gt;
&lt;br /&gt;
== TASK 3 ==&lt;br /&gt;
&lt;br /&gt;
make a function that returns the bitcoin price. From another file, print the price&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&lt;br /&gt;
This is a basic intro to classes. Classes organize code and provide the basis for the object/type system of python. An object has data and behavior. Classes define new objects. This python course will not require object oriented design, but you should know the basics of a python class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;# define a class&lt;br /&gt;
class Animal:&lt;br /&gt;
    # this is a magic method.&lt;br /&gt;
    # __init__ is called when the class is instantiated&lt;br /&gt;
    # `my_animal = Animal(&amp;#039;masha&amp;#039;)` makes a new Animal, executes this method, and assigns the new animal to &amp;#039;my_animal&amp;#039;&lt;br /&gt;
    def __init__(self, name):&lt;br /&gt;
        # self refers to newly created instance of the class.&lt;br /&gt;
        print(id(self))&lt;br /&gt;
        # this creates an instance attribute &amp;#039;name&amp;#039; &lt;br /&gt;
        self.name = name&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# define a Dog, which is Animal&lt;br /&gt;
# Dog also has the same __init__ method from animal&lt;br /&gt;
class Dog(Animal):&lt;br /&gt;
    def change_name(self, name):&lt;br /&gt;
        self.name = name&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# define a Cat, which is an Animal&lt;br /&gt;
class Cat(Animal):&lt;br /&gt;
    def kak_zavut(self):&lt;br /&gt;
        return &amp;#039;minu nimi on {}&amp;#039;.format(self.name)&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eroman</name></author>
	</entry>
</feed>