What is Python

  • Python is a widely used high-level, general-purpose, interpreted, dynamic programming language
  • Python supports multiple programming paradigms, including , object-oriented, imperative and functional programming or procedural styles.


	>>> import this
	The Zen of Python, by Tim Peters

	Beautiful is better than ugly.
	Explicit is better than implicit.
	Simple is better than complex.
	Complex is better than complicated.
	Flat is better than nested.
	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.
						

Fibonacci series up to n


>>> def fib(n):
>>>     a, b = 0, 1
>>>     while a < n:
>>>         print(a, end=' ')
>>>         a, b = b, a+b
>>>     print()
>>> fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
						

quicksort


def quicksort(array):
    less = []; greater = []
    if len(array) <= 1:
        return array
    pivot = array.pop()
    for x in array:
        if x <= pivot:
            less.append(x)
        else:
            greater.append(x)
return quicksort(less) + [pivot] + quicksort(greater)
>>> quicksort([9,8,4,5,32,64,2,1,0,10,19,27])
[0, 1, 2, 4, 5, 8, 9, 10, 19, 27, 32, 64]
						

interpreted language

 python.webp

dynamic vs. static


  • Static: Variables have a type
  • Dynamic: Runtime objects (values) have a type
  • Static: C++, C#, Java, Haskell
  • Dynamic: Python, JavaScript, Ruby

Everything is Object

But...

... I haven't writen a class even ...

... But I have surely seen class in python ...

Well, Python does have class

But completely different from Java

Just one thing

  • Use spaces (4 spaces per indentation level)
OK, Let's python