<?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%2Flecture1</id>
	<title>I719 Fundamentals of Python/lecture1 - 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%2Flecture1"/>
	<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=I719_Fundamentals_of_Python/lecture1&amp;action=history"/>
	<updated>2026-05-07T02:38:42Z</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/lecture1&amp;diff=117656&amp;oldid=prev</id>
		<title>Eroman: Created page with &quot;= Lesson 1 =  == python 2 or 3? ==  * v2 is more commonly used * v3 is the official standard * we are using python 2 today * all the code we write today will run on both versi...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.itcollege.ee/index.php?title=I719_Fundamentals_of_Python/lecture1&amp;diff=117656&amp;oldid=prev"/>
		<updated>2017-02-06T17:01:18Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Lesson 1 =  == python 2 or 3? ==  * v2 is more commonly used * v3 is the official standard * we are using python 2 today * all the code we write today will run on both versi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Lesson 1 =&lt;br /&gt;
&lt;br /&gt;
== python 2 or 3? ==&lt;br /&gt;
&lt;br /&gt;
* v2 is more commonly used&lt;br /&gt;
* v3 is the official standard&lt;br /&gt;
* we are using python 2 today&lt;br /&gt;
* all the code we write today will run on both versions&lt;br /&gt;
* We will use python 3 next class&lt;br /&gt;
&lt;br /&gt;
== Language basics ==&lt;br /&gt;
&lt;br /&gt;
=== interactive ===&lt;br /&gt;
&lt;br /&gt;
many interactive shells&lt;br /&gt;
&lt;br /&gt;
* default repl, &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;&lt;br /&gt;
* ipython&lt;br /&gt;
* bpython&lt;br /&gt;
&lt;br /&gt;
=== Whitespace dependent ===&lt;br /&gt;
&lt;br /&gt;
* 4 space indent&lt;br /&gt;
* no brackets &amp;lt;code&amp;gt;{&amp;lt;/code&amp;gt; &amp;lt;code&amp;gt;}&amp;lt;/code&amp;gt; like in java&lt;br /&gt;
* no semicolons&lt;br /&gt;
&lt;br /&gt;
=== Comments ===&lt;br /&gt;
&lt;br /&gt;
* use &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; for comments&lt;br /&gt;
&lt;br /&gt;
=== Types ===&lt;br /&gt;
&lt;br /&gt;
* to find the type of a symbol &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt;, use &amp;lt;code&amp;gt;type(a)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Strings ===&lt;br /&gt;
&lt;br /&gt;
* double or single quotes are fine&lt;br /&gt;
* length of string determined by function &amp;lt;code&amp;gt;len()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== functions ===&lt;br /&gt;
&lt;br /&gt;
* to define a function, start with &amp;lt;code&amp;gt;def&amp;lt;/code&amp;gt;&lt;br /&gt;
* then the function name&lt;br /&gt;
* functions are always in snake case. always lower case and words are separated by underscores&lt;br /&gt;
* add the end of the name, list of arguments in parethesis&lt;br /&gt;
* to document function, use triple quoted string after function definition&lt;br /&gt;
* functions can use named arguments, which allow a default value for the argument. They are called &amp;#039;Keyword Arguments&amp;#039;&lt;br /&gt;
* Arguments can be made in order they are in the function definition, or be named specifically&lt;br /&gt;
&lt;br /&gt;
=== Arithmetic ===&lt;br /&gt;
&lt;br /&gt;
similar to java, &amp;lt;code&amp;gt;1 + 1&amp;lt;/code&amp;gt; returns &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Lists ===&lt;br /&gt;
&lt;br /&gt;
lists in Python are like arrays in Java.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;a = [1, 2, 3]  # defines a list&amp;lt;/source&amp;gt;&lt;br /&gt;
=== For loops ===&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; is different from other languages. It is a &amp;amp;quot;foreach&amp;amp;quot; loop. It goes through each element of an iterator.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
0&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
for i in range(3):&lt;br /&gt;
    print(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
== Importing and Libraries ==&lt;br /&gt;
&lt;br /&gt;
* the standard library of python is giant&lt;br /&gt;
&lt;br /&gt;
=== importing random to run randint() ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import random&lt;br /&gt;
random.randint(1, 10)&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;from random import randint&lt;br /&gt;
randint(1, 10)&amp;lt;/pre&amp;gt;&lt;br /&gt;
or to name the import something else&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;from random import randint as randominteger&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Classes ==&lt;br /&gt;
&lt;br /&gt;
* classes are made with the keyword &amp;#039;class&amp;#039;&lt;br /&gt;
* class names are CamelCase&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
* the &amp;lt;code&amp;gt;__init__&amp;lt;/code&amp;gt; method is ran on instantiation&lt;br /&gt;
* first argument of a normal method must always be &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; is the instance created by instantation&lt;br /&gt;
* &amp;lt;code&amp;gt;__init__&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;__str__&amp;lt;/code&amp;gt; are &amp;amp;quot;magic methods&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;class Car:  # define the class with a name&lt;br /&gt;
    def __init__(self, name, wheels): # defines a method&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    This method is ran on each instantiation of this class&lt;br /&gt;
    example, `Car(&amp;#039;hi&amp;#039;)` will run this method&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    self._name = name  # assigns a property to the instance&lt;br /&gt;
        self.wheels = wheels&lt;br /&gt;
&lt;br /&gt;
    def __str__(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Give the instance a name. Is called during `print(instance)`&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return &amp;quot;{0} with {1} wheels&amp;quot;.format(self.name, self.wheels)&lt;br /&gt;
&lt;br /&gt;
    def print_wheels(self):&lt;br /&gt;
        print(self.wheels)&lt;br /&gt;
&lt;br /&gt;
c = Car(&amp;#039;Wagon&amp;#039;, 10) # make an object from a class, ie Instantiation&lt;br /&gt;
&lt;br /&gt;
print(c)  # when print a instance, the __str__ method is called&lt;br /&gt;
c.print_wheels()&amp;lt;/source&amp;gt;&lt;br /&gt;
== Tasks ==&lt;br /&gt;
&lt;br /&gt;
=== Task 1 ===&lt;br /&gt;
&lt;br /&gt;
print 10 lines, each printing &amp;#039;hello $N&amp;#039;, where N is the line number&lt;br /&gt;
&lt;br /&gt;
==== Example Solution ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Task 1&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
def add_number_to_hello(n=1):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Takes a number, and adds it to the&lt;br /&gt;
    end of string &amp;#039;hello &amp;#039;&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    result = &amp;#039;hello {0}&amp;#039;.format(n)&lt;br /&gt;
    return result&lt;br /&gt;
&lt;br /&gt;
for i in range(1, 11):&lt;br /&gt;
    print(add_number_to_hello(n=i))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== Task 2 ===&lt;br /&gt;
&lt;br /&gt;
&amp;amp;quot;Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Example Solution ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;for x in range(1,101):&lt;br /&gt;
    if x % 15 == 0:&lt;br /&gt;
        print &amp;quot;FizzBuzz&amp;quot; # Catch multiples of both first.&lt;br /&gt;
    elif x % 3 == 0:&lt;br /&gt;
        print &amp;quot;Fizz&amp;quot;&lt;br /&gt;
    elif x % 5 == 0:&lt;br /&gt;
        print &amp;quot;Buzz&amp;quot;&lt;br /&gt;
    else:&lt;br /&gt;
        print x&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eroman</name></author>
	</entry>
</feed>