Web Programming Course
SUT • Fall 2018
Introduction
Getting Started
Python Basics
Standard Data Types
Operators
Control Structures
It combines the power of systems languages, such
as C and Java, with the ease and rapid development of scripting languages, such as Ruby
Simple and Minimalistic
Easy to Learn
High-level Language
Portable
Extensible
Embeddable
Extensive Libraries
Free, Open Source, ... and Fun!
Beautiful is better than ugly
Explicit is better than implicit
Simple is better than complex
Sparse is better than dense
Readability counts
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced
In the face of ambiguity, refuse the temptation to guess
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea
More on Medium
Python 2.0 was released in 2000, with many new
features added
Python 3.0, adjusting several aspects of the core language, was released in 2008
Python 3.0 is backwards-incompatible
Python 2.x is legacy, Python 3.x is the present and
future of the language
Python porting progress
We use Python 3.x in this course
$ sudo apt-get install python3
....
$ python3
% python3
Python 3.6.7rc1 (default, Sep 27 2018, 09:51:25)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
exit()
$ipython3
% ipython3
Python 3.6.7rc1 (default, Sep 27 2018, 09:51:25)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
Download Python from http://python.org
install
Python's interactive interpreter is one of the most powerful tools used in everyday Python development
Python shell evaluates the expression entered
after prompt and displays the result
In [1]: 2 + 5
Out[1]: 7
In [2]: 2 ** 100
Out[2]: 1267650600228229401496703205376
In [3]: print(3 * 10)
30
In [4]:
print('Hello World!')
# hello.py
# By: Behnam Hatami-Varzaneh
print('Hello World!')
# short comment
In [1]: x = 2
In [2]: x
Out[2]: 2
In [3]: x = 'Ali'
In [4]: x
Out[4]: 'Ali'
In [1]: type(True)
Out[1]: bool
In [2]: type('Hello')
Out[2]: str
In [3]: type(5)
Out[3]: int
In [4]: type(5.2)
Out[4]: float
In [5]: 'Ali' + 0
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-877cabd96baa> in <module>
----> 1 'Ali' + 0
TypeError: must be str, not int
In [1]: '123' + str(45)
Out[1]: '12345'
In [2]: int('123') + 45
Out[2]: 168
In [1]: radius = input('Enter radius: ')
Enter radius: 123.5
In [2]: r = float(radius)
In [3]: area = 3.14159 * r ** 2
In [4]: print('The area is:', area)
The area is: 47916.3160775
ans = input("Enter 'y' or 'n': ")
if ans == 'y':
print("Entered 'y'")
elif ans == 'n':
print("Entered 'n'")
else:
print('Invalid key pressed!')
i = 0
while i < 10:
print(i)
i += 1
for x in ['Ali', 'Mahsa', 'Navid', 'Zahra']:
print('Hello ' + x + '!')
for i in range(10):
print(i)