Python Programming Language (2024)

Python Programming Language (4)

Python is an interpreted, high level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scale. In July 2018, Van Rossum stepped down as the leader in the language community.

Python features a dynamic type system and automatic memory management. It supports multiple programming paradigms, including object-oriented, imperative, functional and procedural and has a large comprehensive standard library.

Python interpreters are available for many operating systems. CPython, the reference implementation of Python, is open source software and has a community-based development model, as do nearly all of Python’s other implementations. Python and CPython are managed by the non-profit Python Software Foundation.

History

Python Programming Language (5)

Python was conceived in the late 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to the ABC language (itself inspired by SETL), capable of exception handling and interfacing with the Amoeba operating system. It's implementation begun in 1989. Van Rossum’s long influence on Python is reflected in the title given to him by the Python community; Benevolent Dictator For Life (BDFL) — a post from which he gave himself a permanent vacation on July 12, 2018.

Python 2.0 was released on 16 October 2000 with many major new features, including a cycle-detecting garbage collector and support for Unicode.

Python 3.0 was released on 3 December 2008. It was a major revision of the language that is not completely backwards-compatible. Many of its major features were backported to Python 2.6.x and 2.7.x version series. The release of Python3 includes the 2to3 utility, which automates ( at least partially) the translation of Python 2 code to Python 3.

Python 2.7’s end-of-life date was initially set at 2015 then postponed to 2020 out of concern that a large body of existing code could not easily be forward-ported to python 3. In January 2017, Google announced work on a Python2.7 to Go transcompiler to improve performance under concurrent workloads.

Features and Philosophy

Python is a multi-paradigm programming language. Object-oriented programming and structured programming are fully supported and many of its features support functional programming and aspect-oriented programming (including by metaprogramming and meta objects (magic methods)). Many other paradigms are supported via extensions, including design by contract and logic programming. Python uses dynamic typing and a combination of reference counting and cycle-detecting garbage collector for memory management. It also features dynamic name resolution ( late binding), which binds methods and variable names during program execution.

Python’s design offers some support for functional programming in the List tradition. It has filter(), map(), and reduce() functions; list comprehensions,dictionaries and sets; and generator expressions. The standard library has tow modules ( itertools and functools) that implement functional tools borrowed from Haskell and Standard ML.

The language’s core philosophy is summarized in the document The Zen of Python (PEP 20), which includes aphorisms such as;

  • Beautiful is better than ugly
  • Explicit is better than implicit
  • Simple is better than complex
  • Complex is better than complicated
  • Readability counts

Rather than having all of its functionality built into its core, Python was designed to be highly extensible. This compact modularity has made it particularly popular as a means of adding programmable interfaces to existing applications. Van Rossum’s vision of a small core language with a large standard library and easily extensible with ABC, which espoused the opposite approach.

While offering choices in coding methodology, the Python philosophy rejects exuberant syntax ( such as that of Perl) in favor of a simpler,less-cluttered grammar. As Alex Merteli put it: “To describe something as ‘clever’ is not considered a compliment in the Python culture”. Python’s philosophy rejects the Perl, “there is a more than one way to do it” approach to language design in favor of “there should be one- and preferably only one — obvious way to do it.”

Python’s developers strive to avoid premature optimization, and reject patches to non-critical parts of the CPython reference implementations that would offer marginal increases in speed at the cost of clarity. When speed is important, a Python programmer can move time-critical functions to extension modules written in languages such as C, or use PyPy, a just-in-time compiler. Cython is also available, which translates a Python script into C and makes direct C-level API calls into the Python interpreter.

An important goal of Python’s developers is keeping it fun to use. This is reflected in language’s name — a tribute to the British comedy group Monty Python — and in occasionally playful approaches to tutorials and reference materials, such as examples that refer to spam and eggs ( from a famous Monty Python sketch) instead of standard foo and bar.

A common neologism in Python community is pythonic, which can have a wide range of meanings related to program style. To say that code is pythonic is to say that it uses Python idioms well, that it is natural or shows fluency in the language, that it conforms with Python’s minimalistic philosophy and emphasis on readability. In contrast, code that is difficult to understand or reads like a rough transcription from another programming language is called unpythonic. Users and admirers of Python, especially this considered knowledgeable or experienced, are often referred to as Pyhtonists, Pythonistas, and Pythoneers.

Syntax and Semantics

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 and Pascal.

Indentation

Python uses 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. The feature is sometimes termed as the off-side rule.

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 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 as binding the name to the object. Since the name’s storage location 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=2; y=2;z=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 type; thus there is dynamic typing.

  • 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 statement 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 clause; it also ensures that clean-up code in a finally block will always be run regardless of how the block exits.
  • The raise statement, use to raise a specified exception or re-raise a caught exception.
  • The class statement, which executes a block of code and attached 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 on September 2006, which encloses a code block within context manager (for example, acquiring a lock before the block of code is run and releasing the lock afterwards, or opening a file and the closing it), allowing Resource Acquisition is Initialization (RAII) like behavior and replaces a common try/finally idiom.
  • 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. 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 function or variable can be used in the current program. There are three ways of using import:
  • import <module> [as] <alias>
  • from <module name> import *
  • 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 3.

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 were lazy 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.

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 two types of divisions in Python. They are floor division and Integer 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.
  • In Python, == compares by value, versus Java, which compares numerics by value and objects by reference. (Value comparison in Java on objects can be performed with the equals() method). Python’s is operator may be to compare object identities (comparison by reference). In Python, comparisons may be chained, for example a <= b <= c
  • Python uses the words and, or, not for its boolean operators rather than the symbolic &&,||,! used in Java and C.
  • Python has a type of expression termed list comprehension. Python 2.4 extended list comprehensions into a more general expression termed a generator expressions.
  • Anonymous functions are implemented using lambda expressions; however, these are limited in that the body can only be one expression.
  • Condition 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 list 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-tuple, 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 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 where multiple expressions, each evaluating to anything that can be assigned to (a variable, a writable property, etc), are associated in an 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 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 function analogous to printf format strings in C, e.g. “spam=%s eggs=%d” % (“blah”, 2) evaluates to “spma=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}’

Methods

Methods on objects are functions 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 some other object-oriented programming languages (e.g., C++,Java,Objective-C. Or Ruby).

Typing

Python uses duck typing and has typed objects but untyped variable names. Type constraints are not checked at compile time; rather, operations on an object may fail, signifying that the given object is not of suitable type.

Despite being dynamically typed, Python is strongly typed, forbidding operations that are not well-defined ( for example, adding a number to a string) rather than silently attempting to make sense of them. Python allows programmers to defined their own types using classes, which are most often used for object-oriented programming. New instances of classes are constructed by calling the class ( for example, SpamClass() or EggsClass()) and the classes are instances of itself), allowing metaprogramming and reflection.

Before version 3.0, Python had two kinds of classes: old-style and new-style. The syntax of both styles is the same, the difference being whether the class object is inherited from, directly or indirectly (all new style classes inherit from object and are instances of type). In versions of Python 2 from 2.2 onwards, both kinds of classes can be used. Old style classes where eliminated in Python 3.0.

The long term plan is to support gradual typing and from Python 3.5, the syntax of the language allows specifying static types but they are not checked in the default implementation, CPython. An experimental optional static type checker name mypy supports compile-time type checking.

Mathematics

Python has the usual C language arithmetic operators ( + , — , * , , %). It also has ** for exponentiation, e.g., 5**3 == 125 and 9**0.5 == 3.0, and a new matrix multiply @ operator is included in version 3.5. Additionally, it has a unary operator (~), which essentially inverts all the bits of its one argument. For integer, this mean ~x = -x — 1 . Other operators include bitwise shift operators x << y , which shifts x to the left y places, the same as x (2*y), and x >> y, which shifts x to the right y places, the same as x//(2**y).

Due to Python’s extensive mathematics library, and third-party library NumPy that further extends the native capabilities, it is frequently used as a scientific scripting language to aid in problem-solving such as numerical data processing and manipulation.

Libraries

Python’s large standard library, commonly cited one of its greatest strengths, provides tools suited to many tasks. For Internet-facing applications 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 specifications ( for example, the Web Server Gateway Interface (WSGI) implementation wsgiref follows PEP-333, but most modules are not. They are specified by their code, internal documentation, and test suites (if supplied). However, because most of the standard library is cross-platform Python code, only a few modules need altering or rewriting for variant implementations.

As of March 2018, the Python package Index (PyPI), the official repository for third-party Python software, contains over 130,000 packages with a wide range of functionality including:

  • Graphical user interfaces
  • Web frameworks
  • Multimedia
  • Databases
  • Networking
  • Test frameworks Automation
  • Web scraping
  • Documentation
  • System administration
  • Scientific computing
  • Text Processing
  • Image Processing

Development Environments

Most Python implementations (including CPython) include a read-eval-print loop (REPL), permitting them to function as a command line interpreter for which the user enters statements sequentially and receives results immediately.

Other Shells, including IDLE and IPython, add further capability as auto-completion, session state retention, and syntax highlight.

As well as standard desktop integrated development environments, there are Wen browser-based IDE’s; SageMath (intended for developing scientific and math-related python programs); PythonAnywhere, a browser-based IDE and hosting environment; and Canopy IDE, a commercial Python IDE emphasizing scientific computing. You can also use Pycharm from JetBrains.

Support me by cheking out my small app : Life Planner

Cheers!

Python Programming Language (2024)

FAQs

Is Python enough for everything? ›

Python alone isn't going to get you a job unless you are extremely good at it. Not that you shouldn't learn it: it's a great skill to have since python can pretty much do anything and coding it is fast and easy.

Where can I find Python answers? ›

The Users category of the discuss.python.org website hosts usage questions and answers from the Python community. The tutor list offers interactive help. If the tutor list isn't your cup of tea, there are many other mailing lists and newsgroups. Stack Overflow has many Python questions and answers.

Is Python language enough to get a job? ›

Yes, but it helps to know at least the basics of either web dev, infrastructure, or some SQL as others have said. I picked up SQL while I was learning Python and now I have a “pure” Python job, i.e. 90-95% of the job is knowing Python and the other is being able to figure out the rest of the stack if/when needed.

Is 2 years enough to learn Python? ›

If you're looking for a general answer, here it is: If you just want to learn the Python basics, it may only take a few weeks. However, if you're pursuing a career as a programmer or data scientist, you can expect it to take four to twelve months to learn enough advanced Python to be job-ready.

How long does it take to learn Python to get a job? ›

So if you're already proficient in other programming languages, Python is going to be a piece of cake for you. But if you're an absolute beginner and Python is your first programming language ever, I would give it from three to six months.

How many hours a day to learn Python? ›

From Awareness to Ability
GoalLearn Python's syntax and fundamental programming and software development concepts
Time RequirementApproximately four months of four hours each day
WorkloadApproximately ten large projects
1 more row

What is Python best answer? ›

Python is a widely-used general-purpose, object-oriented, high-level programming language. It is used to create web applications, and develop websites and GUI applications. The popularity of the language is due to its versatility.

Why is Python a high level language? ›

Python is an object-oriented, high-level programming language. Object-oriented means this language is based around objects (such as data) rather than functions, and high-level means it's easy for humans to understand.

Where can I practice Python coding questions? ›

Where can I practice Python programming?
  • Dataquest.io has dozens of free interactive practice questions, as well as free interactive lessons, project ideas, tutorials, and more.
  • HackerRank is a great site for practice that's also interactive.
  • CodingGame is a fun platform for practice that supports Python.

Is Python a high paying job? ›

Python is a non-typed high level language. It has a full range of utilities, from scripting and tooling to writing entire web applications with Django framework. It is also heavily used in data science. While the average salary of a python developer is $125K per year, some offers reached the amount of $500K per year.

What is the easiest job to get with Python? ›

Now that you know how easy it can be to learn, here are our top 7 jobs you can get knowing Python:
  • Python Developer. ...
  • Full Stack Developer. ...
  • Data Scientist / Data Analyst. ...
  • Data Engineer. ...
  • Machine Learning Engineer. ...
  • Product Manager. ...
  • Performance Marketer.
Feb 8, 2023

Is Python a high paying skill? ›

The majority of Python Architect salaries across the United States currently range between $143,000 (25th percentile) and $169,500 (75th percentile) annually.

Is 30 too old to learn Python? ›

Questions like 'Am I too old to learn coding?' often plague those considering a career change starting at 25, 30, and beyond. Age, however, does not define one's ability to acquire new skills, especially in the realm of coding where demand for proficiency in languages such as Python and Javascript continues to surge.

Is 2 hours a day enough to learn Python? ›

If you can dedicate more time, let's say two hours per day, you could complete the Specialization in two months. In this and many other introductory courses, you might expect to learn the following foundational syntax and elements of Python: Variables and types.

What is the hardest coding language to learn? ›

What are the hardest coding languages to learn?
  • Haskell.
  • INTERCAL.
  • BrainF**K.
  • WhiteSpace.
  • Malbolge.
  • COW.
  • C++
Mar 27, 2024

Is it good to learn only Python? ›

Having Python knowledge and skills can open doors to various career opportunities such as Software Engineer, DevOps Engineer, Data Scientist, Research Analyst and more, giving you an edge in the job market.

When should we not use Python? ›

There are some limitations to using Python to access databases. Compared to other popular technologies such as JDBC and ODBC, the Python database access layer is a little underdeveloped and primitive. It is, therefore, not considered suitable if developers are looking for a smooth interaction of complex legacy data.

Can I learn Python in 3 months? ›

In general, it takes around two to six months to learn the fundamentals of Python. But you can learn enough to write your first short program in a matter of minutes. Developing mastery of Python's vast array of libraries can take months or years.

When not to use Python? ›

Cons of Python Programming
  1. Python is Slow at Runtime.
  2. Mobile Application Development.
  3. Difficulty in Using Other Languages.
  4. High Memory Consumption.
  5. Not used in the Enterprise Development Sector.
  6. Runtime Errors.
  7. Simplicity.
Nov 2, 2023

Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6643

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.