Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 22, 2022 11:55 pm GMT

Python 101 : The Ultimate Python Tutorial For Beginners

Knowing Python

Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small- and large-scale projects.

More about Python

Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.

Who invented Python?

Python was conceived in the late 1980s by *Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands. Van Rossum shouldered sole responsibility for the project, as the lead developer, until 12 July 2018, when he announced his "permanent vacation" from his responsibilities as Python's "benevolent dictator for life", a title the Python community bestowed upon him to reflect his long-term commitment as the project's chief decision-maker. In January 2019, active Python core developers elected a five-member Steering Council to lead the project.

Python's Evolution

Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0. Python 2.0 was released in 2000 and introduced new features such as list comprehensions, cycle-detecting garbage collection, reference counting, and Unicode support. Python 3.0, released in 2008, was a major revision that is not completely backward-compatible with earlier versions. Python 2 was discontinued with version 2.7.18 in 2020. Right now in April 2022 the latest version is 3.10.4.

Why is Python so popular nowadays?

  • Python consistently ranks as one of the most popular programming languages.
  • Python is a programming language that lets you work quickly and integrate systems more effectively. It's very easy to learn

Programming examples

Hello world program:
print('Hello, world!')

Program to calculate the factorial of a positive integer:

n = int(input('Type a number, and its factorial will be printed: '))if n < 0:    raise ValueError('You must enter a non-negative integer')factorial = 1for i in range(2, n + 1):    factorial *= iprint(factorial)

Libraries

Python's large standard library, commonly cited as one of its greatest strengths, provides tools suited to many tasks. For Internet-facing applications, many standard formats and protocols such as MIME and HTTP are supported. It includes modules for creating graphical user interfaces, connecting to relational databases, generating pseudorandom numbers, arithmetic with arbitrary-precision decimals, manipulating regular expressions, and unit testing.

Some parts of the standard library are covered by specificationsfor example, the Web Server Gateway Interface (WSGI) implementation wsgiref follows PEP 333 but most are specified by their code, internal documentation, and test suites. However, because most of the standard library is cross-platform Python code, only a few modules need altering or rewriting for variant implementations.

Python uses

  1. Automation
  2. Data analytics
  3. Databases
  4. Documentation
  5. Graphical user interfaces
  6. Image processing
  7. Machine learning
  8. Mobile apps
  9. Multimedia
  10. Computer networking
  11. Scientific computing
  12. System administration
  13. Test frameworks
  14. Text processing
  15. Web frameworks
  16. Web scraping

Python Keywords

Python has 35 keywords or reserved words; they cannot be used as identifiers.

  • and
  • as
  • assert
  • async
  • await
  • break
  • class
  • continue
  • def
  • del
  • elif
  • else
  • except
  • False
  • finally
  • for
  • from
  • global
  • if
  • import
  • in
  • is
  • lambda
  • None
  • nonlocal
  • not
  • or
  • pass
  • raise
  • return
  • True
  • try
  • while
  • with
  • yield

Indentation

Python uses whitespace to delimit control flow blocks (following the off-side rule). Python borrows this feature from its predecessor ABC: instead of punctuation or keywords, it uses indentation to indicate the run of a block.

In so-called "free-format" languagesthat use the block structure derived from ALGOLblocks of code are set off with braces ({ }) or keywords. In most coding conventions for these languages, programmers conventionally indent the code within a block, to visually set it apart from the surrounding code.

A recursive function named foo, which is passed a single parameter, x, and if the parameter is 0 will call a different function named bar and otherwise will call baz, passing x, and also call itself recursively, passing x-1 as the parameter, could be implemented like this in Python:

def foo(x):    if x == 0:        bar()    else:        baz(x)        foo(x - 1)

and could be written like this in C with K&R indent style:

void foo(int x){    if (x == 0) {        bar();    } else {        baz(x);        foo(x - 1);    }}

Incorrectly indented code could be misread by a human reader differently than it would be interpreted by a compiler or interpreter. For example, if the function call foo(x - 1) on the last line in the example above was erroneously indented to be outside the if/else block:

def foo(x):    if x == 0:        bar()    else:        baz(x)    foo(x - 1)

Data structures

Since Python is a dynamically typed language, Python values, not variables, carry type information. All variables in Python hold references to objects, and these references are passed to functions. Some people (including Guido van Rossum himself) have called this parameter-passing scheme "call by object reference". An object reference means a name, and the passed reference is an "alias", i.e. a copy of the reference to the same object, just as in C/C++. The object's value may be changed in the called function with the "alias", for example:

>>> alist = ['a', 'b', 'c']>>> def my_func(al):...     al.append('x')...     print(al)...>>> my_func(alist)['a', 'b', 'c', 'x']>>> alist['a', 'b', 'c', 'x']

Function my_func changes the value of alist with the formal argument al, which is an alias of alist. However, any attempt to operate (assign a new object reference to) on the alias itself will have no effect on the original object.[clarification needed]

>>> alist = ['a', 'b', 'c']>>> def my_func(al):...     # al.append('x')...     al = al + ['x'] # a new list created and assigned to al means al is no more alias for alist...     print(al)...>>> my_func(alist)['a', 'b', 'c', 'x']>>> alist['a', 'b', 'c']

Bibliography:

Python Programming Language
Python Organization
Python Syntax and semantics

Note: This Technical article was written as an assignment for Python Boot Camp by @DSEAfrica and @lux_academy.

Original Link: https://dev.to/aliaformo/python-101-the-ultimate-python-tutorial-for-beginners-c8e

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To