#06 Snake in Tech - Python Language

                                                     Python Language
                                Python Programming Language Overview & Why It Is So Popular?
Python is AN understood, high-level, general artificial language. Created by Guido van Rossum and initial discharged in 1991, Python's style philosophy emphasizes code readability with its notable use of serious white space. Its language constructs and object-oriented approach aim to assist programmers write clear, logical code for tiny and large-scale comes.
                                                  

Python is dynamically typewritten and garbage-collected. It supports multiple programming paradigms, together with structured (particularly, procedural), object-oriented, and practical programming. Python is usually delineate as a "batteries included" language thanks to its comprehensive customary library.

Python was planned within the late Eighties as a successor to the basics language. Python 2.0, discharged in 2000, introduced options like list comprehensions and a pickup system capable of grouping reference cycles. Python 3.0, discharged in 2008, was a significant revision of the language that's not utterly backward-compatible, and far Python two code doesn't run unqualified on Python three.

The Python two language was formally out of print in 2020 (first planned for 2015), and "Python two.7.18 is that the last Python twounharness and thus the last Python two unharness." No additional security patches or different enhancements are going to be discharged for it.With Python 2's end-of-life, solely Python three and later square measure supported.

Python interpreters square measure accessible for several operative systems. a worldwide community of programmers develops and maintains CPython, AN open source reference implementation. A non-profit organization, the Python software package Foundation, manages and directs resources for Python and CPython development.
                                   Discover 5 Leading Companies That Use Python and Learn Does It Fit ...
Features 
Python may be a multi-paradigm artificial language. Object-oriented programming and structured programming are absolutely supported, and lots of of its options support useful programming and aspect-oriented programming (including by meta programming and meta objects (magic methods). several alternative paradigms are supported via extensions, as well as style by contrac and logic programming.

Python uses dynamic typewriting and a mix of reference enumeration and a cycle-detecting employee for memory management. It conjointly options dynamic name resolution (late binding), that binds methodology and variable names throughout program execution.
                             Machine learning with Python: An introduction | JavaWorld
 
Python's style offers some support for useful programming within the Lisp tradition. it's filter, map, and scale back functions; list comprehensions, dictionaries, sets, and generator expressions.The quality library has 2 modules (itertools and functools) that implement useful tools borrowed from Haskell and customary cubic centimetre.
                                 Where can I use Python programming? - Quora

The language's core philosophy is summarized within the document The Zen of Python (PEP 20), which incorporates aphorisms such as:

  • Beautiful is best than ugly.
  • Explicit is best than implicit.
  • Simple is best than advanced.
  • Complex is best than difficult.
  • Readability counts.
Rather than having all of its practicality designed into its core, Python was designed to be extremely protractible. This compact modularity has created it significantly standard as a way of adding programmable interfaces to existing applications. Van Rossum's vision of a little core language with an oversized customary library and simply protractible interpreter stemmed from his frustrations with fundamentalsthat espoused the other approach.

Python strives for a less complicated, less-cluttered syntax and descriptive linguistics whereas giving developers a alternative in their committal to writing methodology. In distinction to Perl's "there is quite a way to try and do it" expression, Python embraces a "there ought to be oneand ideally solely one obvious thanks to do it" style philosophy. Alex Martelli, a Fellow at the Python computer code Foundation and Python book author, writes that "To describe one thing as 'clever' isn't thought of a compliment within the Python culture."

Python's developers try to avoid premature optimisation, and reject patches to non-critical components of the CPython reference implementation that will provide marginal will increase in speed at the price of clarity. Once speed is very important, a Python software engineer will move time-critical functions to extension modules written in languages like C, or use PyPy, a just-in-time compiler. Cython is additionally out therethat interprets a Python script into C and makes direct C-level API calls into the Python interpreter.
                                         10 Reasons Why to Learn Python In 2020 - The Indian Wire

An important goal of Python's developers is keeping it fun to use. this is often mirrored within the language's name—a tribute to the British comedy cluster Monty Python and in often quizzical approaches to tutorials and reference materials, like examples that see spam and eggs (from a famed Monty Python sketch) rather than the quality foo and bar.

A common neologism within the Python community is pythonic, which might have a good vary of meanings associated with program vogueto mention that code is pythonic is to mention that it uses Python idioms well, that it's natural or shows fluency within the language, that it conforms with Python's minimalist philosophy and stress on readability. In distinction, code that's troublesome to grasp or reads sort of a rough transcription from another artificial language is termed unpythonic.
                              Python - Overview of the Programming Language | Pythontic.com

Users and admirers of Python, particularly those thought of knowledgeable or knowledgeablear typically noted as Pythonistas.

Python is meant to be an easily readable language. Its formatting is visually uncluttered, and it often uses English keywords where other languages use punctuation. Unlike many other languages, it does not use curly brackets to delimit blocks, and semicolons after statements are optional. It has fewer syntactic exceptions and special cases than C or Pascal.


                               Why Learn Python as Your First Programming Language? | Penjee ...

Indentation

Python whitespace indentation, rather than curly brackets or keywords, to delimit blocks. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block. Thus, the program's visual structure accurately represents the program's semantic structure.This feature is sometimes termed the off-side rule, which some other languages share, but in most languages indentation doesn't have any semantic meaning.


                            Python Advantages and Disadvantages - Step in the right direction ...

Statements and control flow

Python's statements include (among others):

  • The assignment statement (token '=', the equals sign). This operates differently than in traditional imperative programming languages, and this fundamental mechanism (including the nature of Python's version of variables) illuminates many other features of the language. Assignment in C, e.g., x = 2, translates to "typed variable name x receives a copy of numeric value 2". The (right-hand) value is copied into an allocated storage location for which the (left-hand) variable name is the symbolic address. The memory allocated to the variable is large enough (potentially quite large) for the declared type. In the simplest case of Python assignment, using the same example, x = 2, translates to "(generic) name x receives a reference to a separate, dynamically allocated object of numeric (int) type of value 2." This is termed binding the name to the object. Since the name's storage location doesn't contain the indicated value, it is improper to call it a variable. Names may be subsequently rebound at any time to objects of greatly varying types, including strings, procedures, complex objects with data and methods, etc. Successive assignments of a common value to multiple names, e.g., x = 2y = 2z = 2 result in allocating storage to (at most) three names and one numeric object, to which all three names are bound. Since a name is a generic reference holder it is unreasonable to associate a fixed data type with it. However at a given time a name will be bound to some object, which will have a type; thus there is dynamic typing.

                        Role of Python Programming Language in AI | Most Popular AI ...

  • The if statement, which conditionally executes a block of code, along with else and elif (a contraction of else-if).
  • The for  statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
  • The While statement, which executes a block of code as long as its condition is true.
  • The try statement, which allows exceptions raised in its attached code block to be caught and handled by except clauses; it also ensures that clean-up code in a finally block will always be run regardless of how the block exits.
  • The raise statement, used to raise a specified exception or re-raise a caught exception.
  • The class statement, which executes a block of code and attaches its local namespace to a class, for use in object oriented programming.
  • The def statement, which defines a function or method
  • The with statement, from Python 2.5 released in September 2006, which encloses a code block within a context manager (for example, acquiring a lock before the block of code is run and releasing the lock afterwards, or opening a file and then closing it), allowing Resource Acquistation in Initialization (RAII)-like behavior and replaces a common try/finally idiom.
  • The break statement, exits from the loop.
  • The continue statement, skips this iteration and continues with the next item.
  • The pass statement, which serves as a NOP. It is syntactically needed to create an empty code block.
  • The assert statement, used during debugging to check for conditions that ought to apply.
  • The yield statement, which returns a value from a generator function. From Python 2.5, yield is also an operator. This form is used to implement coroutines.
  • The import statement, which is used to import modules whose functions or variables can be used in the current program. There are three ways of using import:
  •  import <module name> [as <alias>] or from <module name> import * or from <module name> import <definition 1> [as <alias 1>], <definition 2> [as <alias 2>], ....
  • The print statement was changed to the print() function in Python .

                                   An Exhaustive Reply to - What is Python Used For? | Hacker Noon

Python does not support tail call optimization or first class continuation, and, according to Guido van Rossum, it never will. However, better support for coroutine-like functionality is provided in 2.5, by extending Python's generators. Before 2.5, generators werelazy iterators; information was passed unidirectionally out of the generator. From Python 2.5, it is possible to pass information back into a generator function, and from Python 3.3, the information can be passed through multiple stack levels.

                             Features of Python - Review the irresistible Python attributes ...

Expressions

Some Python expressions are similar to languages such as C and JAVA, while some are not:

  • Addition, subtraction, and multiplication are the same, but the behavior of division differs. There are two types of divisions in Python. They are floor division (or integer division) // and floating point/division. Python also added the ** operator for exponentiation.
  • From Python 3.5, the new @ infix operator was introduced. It is intended to be used by libraries such as Numpy for matrix multiplication.
  • From Python 3.8, the syntax :=, called the 'walrus operator' was introduced. It assigns values to variables as part of a larger expression.
  • In Python, == compares by value, versus Java, which compares numerics by value and objects by reference.  (Value comparisons in Java on objects can be performed with the equals() method.) Python's is operator may be used to compare object identities (comparison by reference). In Python, comparisons may be chained, for example a <= b <= c.
  • Python uses the words andornot for its boolean operators rather than the symbolic &&||! used in Java and C.
  • Python has a type of expression termed a list comprehension. Python 2.4 extended list comprehensions into a more general expression termed a generator expression.
  • Anonymous function  are implemented using lambda expressions; however, these are limited in that the body can only be one expression.
  • Conditional expressions in Python are written as x if c else y (different in order of operands from the c ? x : y operator common to many other languages).
  • Python makes a distinction between lists and tuples. Lists are written as [1, 2, 3], are mutable, and cannot be used as the keys of dictionaries (dictionary keys must be immutable in Python). Tuples are written as (1, 2, 3), are immutable and thus can be used as the keys of dictionaries, provided all elements of the tuple are immutable. The + operator can be used to concatenate two tuples, which does not directly modify their contents, but rather produces a new tuple containing the elements of both provided tuples. Thus, given the variable t initially equal to (1, 2, 3), executing t = t + (4, 5) first evaluates t + (4, 5), which yields (1, 2, 3, 4, 5), which is then assigned back to t, thereby effectively "modifying the contents" of t, while conforming to the immutable nature of tuple objects. Parentheses are optional for tuples in unambiguous contexts.
  • Python features sequence unpacking wherein multiple expressions, each evaluating to anything that can be assigned to (a variable, a writable property, etc.), are associated in the identical manner to that forming tuple literals and, as a whole, are put on the left hand side of the equal sign in an assignment statement. The statement expects an iterable object on the right hand side of the equal sign that produces the same number of values as the provided writable expressions when iterated through, and will iterate through it, assigning each of the produced values to the corresponding expression on the left. Python has a "string format" operator %. This functions analogous to printf format strings in C, e.g. "spam=%s eggs=%d" % ("blah", 2) evaluates to "spam=blah eggs=2". In Python 3 and 2.6+, this was supplemented by the format() method of the str class, e.g. "spam={0} eggs={1}".format("blah", 2). Python 3.6 added "f-strings": blah = "blah"; eggs = 2; f'spam={blah} eggs={eggs}'.
1. The way of the program — How to Think Like a Computer Scientist ...
Python Console 
                            
  • Python has various kinds of String literals:
    • Strings delimited by single or double quote marks. Unlike in Unix shells , perls and Perl-influenced languages, single quote marks and double quote marks function identically. Both kinds of string use the backslash (\) as an escape character .String interpolation became available in Python 3.6 as "formatted string literals".
    • Triple-quoted strings, which begin and end with a series of three single or double quote marks. They may span multiple lines and function like here documents in shells, Perl and Ruby.
    • Raw string  varieties, denoted by prefixing the string literal with an r. Escape sequences are not interpreted; hence raw strings are useful where literal backslashes are common, such as regular expressions and Windows -style paths. Compare "@-quoting" in C#.
  • Python has array index and array slicing expressions on lists, denoted as a[key]a[start:stop] or a[start:stop:step]. Indexes are zero based, and negative indexes are relative to the end. Slices take elements from the start index up to, but not including, the stop index. The third slice parameter, called step or stride, allows elements to be skipped and reversed. Slice indexes may be omitted, for example a[:] returns a copy of the entire list. Each element of a slice is a shallow copy.

In Python, a distinction between expressions and statements is rigidly enforced, in contrast to languages such as common lisp, scheme or Ruby. This leads to duplicating some functionality. For example:

  • List comprehensions vs. for-loops
  • Conditional expressions vs. if blocks
  • The eval() vs. exec() built-in functions (in Python 2, exec is a statement); the former is for expressions, the latter is for statements.

Statements cannot be a part of an expression, so list and other comprehensions or lambda expressions, all being expressions, cannot contain statements. A particular case of this is that an assignment statement such as a = 1 cannot form part of the conditional expression of a conditional statement. This has the advantage of avoiding a classic C error of mistaking an assignment operator = for an equality operator == in conditions: if (c = 1) { ... } is syntactically valid (but probably unintended) C code but if c = 1: ... causes a syntax error in Python.


Hello world program in Python programming language - Codeforcoding
Python Shell

                                  

Methods

Methods on objects areFunctions attached to the object's class; the syntax instance.method(argument) is, for normal methods and functions, syntactic sugar for Class.method(instance, argument). Python methods have an explicit self parameter to access instance data, in contrast to the implicit self (or this) in some other object-oriented programming languages (e.g.,C++, JAVA,C,Ruby etc...)

                                    Learn the fundamentals of the Python programming language - DevGap              

Example Program 

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 positive integer')

fact = 1
i = 2
while i <= n:
    fact *= i
    i += 1

print(fact)                        
                                               print("Thank you !!!")

Popular posts from this blog

#01 Google's A-Z opinion on an effective Resume

#02 How to write an impressive project proposal

#08 Kick start your carrier