A Briefing of Python
A Briefing of Python
Python is an interpreted, high-level, general-purpose programming language. Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. Python has a comprehensive standard library providing most commonly required functionalities, and it’s available for many operating systems. It has been first released in 1991.
In December 1989, Guido Van Rossum had been looking for a “‘hobby’ programming project that would keep him occupied during the week around Christmas” as his office was closed when he decided to write an interpreter for a “new scripting language. He had been thinking about lately: a descendant of ABC that would appeal to Unix/C hackers”. He attributes choosing the name “Python” to “being in a slightly irreverent mood (and a big fan of Monty Python’s Flying Circus)”
Wetting your appetite
Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.Let’s see some basic stuff:
1. Functions Defined
The core of extensible programming is defining functions. Python allows mandatory and optional arguments, keyword arguments, and even arbitrary argument lists.
# Python 3: 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
2. Compound Data Types
Lists (known as arrays in other languages) are one of the compound data types that Python understands. Lists can be indexed, sliced and manipulated with other built-in functions.
# Python 3: List comprehensions >>> fruits = ['Banana', 'Apple', 'Lime'] >>> loud_fruits = [fruit.upper() for fruit in fruits] >>> print(loud_fruits) ['BANANA', 'APPLE', 'LIME'] # List and the enumerate function >>> list(enumerate(fruits)) [(0, 'Banana'), (1, 'Apple'), (2, 'Lime')]
3. Intuitive Interpretation
Calculations are simple with Python, and expression syntax is straightforward: the operators +, -, * and / work as expected; parentheses () can be used for grouping.
# Python 3: Simple arithmetic >>> 1 / 2 0.5 >>> 2 ** 3 8 >>> 17 / 3 # classic division returns a float 5.666666666666667 >>> 17 // 3 # floor division 5
4. Quick & Easy to Learn
Experienced programmers in any other language can pick up Python very quickly, and beginners find the clean syntax and indentation structure easy to learn.
# Python 3: Simple output (with Unicode) >>> print("Hello, I'm Python!") Hello, I'm Python! # Input, assignment >>> name = input('What is your name?\n') >>> print('Hi, %s.' % name) What is your name? Python Hi, Python.
5. All the Flow You’d Expect
Python knows the usual control flow statements that other languages speak — if, for, while and range — with some of its own twists, of course.
# For loop on a list >>> numbers = [2, 4, 6, 8] >>> product = 1 >>> for number in numbers: ... product = product * number ... >>> print('The product is:', product) The product is: 384
So far, so good. Now, if you’re interested in learning Python, take a look at this wide collection of guides, from beginners to advanced programmers and… have fun!