Python is an interpreted, dynamically typed programming language. That means its programs are text files. To execute a Python program, you run a program called an interpreter that reads a text file full of Python code, and does what it says, and as long as an interpreter is available for one's platform of choice (UNIX-based or UNIX-like operating systems typically come with one and the developers maintain ports to Windows and macOS) the operating system and architecture are largely irrelevant since compilation isn't required. The language's name is a Line-of-Sight Name derived from Monty Python's Flying Circus; no relations to the snake.
Traditionally, interpreted languages like Python are not used to develop whole applications. Partly because the process of interpreting code is slower than the process of running code that's already been compiled into machine language. This is much less true than it once was, because after running a program once, Python stores it in "bytecode" that's been almost, but not quite, compiled into machine code. But for the most part, it's because interpreted programming languages have lacked access to the libraries that compiled programming languages had. Libraries like, say, OpenGL, which allows C++ programmers to render fancy graphics without first telling the computer what a sprite is, and how to move it around.
It is in this last area that Python breaks the mold. Python has extensions that are written in other languages, but unlike those previous languages, Python extensions can be generated automatically from existing C code, and with only a little extra work, you can use Python itself to tidy up the interface so that people who don't like C can use the library anyway.
Python therefore supports a bafflingly large array of functions, which Python programmers can tie together to make whole new programs without touching C note which the official interpreter, occasionally called CPython to distinguish it from unofficial interpreters that may be written in another language, is written in, but doesn't require knowledge of to simply use; decent knowledge of C would be required to work on the official interpreter but not the code it works with unless said code uses extensions written in C.
Python is distinguished by its near-complete lack of braces. Where other programming languages require you to partition your blocks of code using punctuation, Python looks at how it's indented. Other languages are customarily indented to indicate how they're organized, but in Python, that's an actual rule of the language that you have to follow, or your program won't work. This frequently makes Python programs more readable than their equivalents in JavaScript and the like, and readability is one of the goals of the language, as mentioned on the Programming Language article.
The language takes pains to prevent the programmer from having to worry about memory management: it has an automatic garbage collector, meaning you don't have to worry about deleting variables after you're done with them; all variables are technically "pointers," but some types of variable can't be modified after they're created, which prevents issues that arise in C++ and the like where you don't know whether you're dealing with a variable or its Evil Twin; it handles type conversion automatically, meaning the difference between 2, 2.0 and "2" is only as important as you want it to be; and the variable declarations that are used in most other languages to define what type of data a variable will hold are entirely absent from Python, where you "declare" a variable by assigning a value to it. Because of the ease of programming in Python and its clean syntax, it's replaced BASIC as the first language of many new coders, as well as Pascal and LISP in introductory university computer science courses. Cementing its status as a Spiritual Successor to BASIC, Python is ubiquitous on modern graphing calculators. It's also popular for scientific computing with the NumPy, SymPy, and SciPy libraries, giving Mathematica and MATLAB a run for their money.
Note that while the current versions of Python (the 3.x branch) are recommended for most purposes, code and examples can still be found which are written for the older 2.7 branch, which was supported as late as 2020. This distinction will seldom affect online examples, but when investigating physical books, it is worth checking that it uses the current syntax and features. Fortunately, it isn't hard to find books that cover both; for example, the popular computer book publisher O'Reilly Media currently covers both branches in its books, Learning Python (which is intended for newcomers to the language) and Programming Python (which is aimed at more advanced Python programmers).
open/close all folders
Code Examples
Hello Pythonprint("Hello World!")
# Outputs Hello World! to the console
Short and sweet syntax like this is why Python is beloved.
Variable Declaration and Concatenationa = 10
b = 7
c = "Bob"print(a + b)
# Outputs 17print(b + c)
# Python will throw an error. You can't add a number and a string together
# The correct way would be print(str(b) + c), which outputs 7Bobprint("Hello, " + c)
# Outputs Hello, Bob
Unlike other languages, Python will not try to concatenate a number type and a string type together. Like other languages, the + operator is still overloaded with adding numbers and concatenating strings
For Loopsfor i in range(0, 10):
print(i)
The program will output numbers 0 through 9, but not 10 — and the 0 in the parentheses can be dropped and it'll execute the same way. This code example also highlights Python's famous bracket-less syntax. Python uses a colon (:) instead of a left bracket ({) and uses the code's formating to figure out the rest.
While loopsi = 0
while i < 10:
print(i)
i += 1
In addition to for loops, Python also has while loops, which execute what's in them so long as the condition remains true. This snippet likewise prints out the numbers 0 through 9.
Popular Python Libraries and Resources3D graphics engines
Other
Works that are written in PythonVideo Games
Other
"Python for Software Design: How to Think like a Computer Scientist" is a rather good, freely available instructional book, and W3Schools.com has extensive and detailed information on the language.
Beautiful is better than ugly.—
Tim Peters'
Zen of Python, a set of guiding principles for the language
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4