21
Basic Python for Beginners
Python is a very popular programming language at the moment, and its popularity is only growing over time. It has found its application in many areas of software development.
Let's look at the main characteristics of Python as a programming language:
- High-level.
- General purpose.
- Interpreted.
- Object-oriented.
- Imperative.
- Strictly (strongly) typed.
- It has dynamic typing.
Let's look at this in more detail
High-level
Programming languages are divided into high-level and low-level. Low-level languages are languages that are close to programming in machine code or structures close to them (for example, byte codes). Classics of low-level programming: Assembler.
High-level languages are designed accordingly for ease of use and speed of program writing. They use certain abstractions - data structures, a certain set of auxiliary functions, etc. These are almost all the languages you know.
It is worth noting that high-level languages are heterogeneous. Some, such as Python, completely free the programmer from direct use of computer resources, others, such as C, allow you to work directly with memory and even use assembler inserts.
General purpose.
Languages are divided into general-purpose languages (Python, C, Pascal) and specialized (DSL) (SQL, HTML).
Interpreted
Languages are divided into interpreted (Python, Basic) and compiled (C, Pascal). In the first case, the program is executed by a special interpreter program, "on the fly", in the second, the program is first converted into executable files understandable to the computer.
It is worth noting that in fact, many modern "interpreted languages" are actually intermediate representation languages that first distill our program into special "byte codes" understandable to the interpreter, after which he interprets them. Python, Java, and many others are just such languages.
Object-oriented.
Languages are divided into procedural, functional, and object-oriented languages, depending on which structures the program is structured with and how the problem is solved.
In object-oriented languages, we work with classes as types and instances of classes as objects of this type. Problem-solving is based on the interaction of different classes.
Nevertheless, Python, being an object-oriented language, supports both procedural programming and a program that can be written without a single class.
Functional languages are based on a different computing system from the previous ones, called lambda calculus.
Imperative
Languages are divided into imperative - when we set a sequence of commands to perform a task, and declarative - when we describe the result we want to get (SQL).
Strictly (strongly) typed.
Strongly typed languages assume that the interpreter will not implicitly cast types when trying to execute a command. (Java, Python, Haskell, Lisp) Implicit-type conversions can occur in weakly typed languages. (C, JavaScript, Visual Basic, PHP.)
Dynamic typing
Dynamic typing assumes that during the execution of a command, a variable can contain objects of various types.
Static typing assumes that when setting a variable, the data type that it can contain is immediately indicated.
- There are many features in the standard library.
- Introspection.
- Automatic memory management.
- Multiplatform.
- Design patterns.
- Usability
- Readability - part of the syntax is a formatting
- Interactive language
A variable is a named memory area whose name can be used to access data. The object (in Python everything is an object) referenced by a variable is called the value of the variable.
Variable assignment (assignment) is the process of specifying an object variable to which it will refer. In Python, assignment is performed using =
An operator or instruction is the smallest part of a programming language. This is a command or a set of commands that can be executed by an executor. The objects on which operators perform actions are called operands. Depending on their number, the operators are divided into:
- Unary (-1 is a unary minus).
- Binary (1 + 2 - addition).
- Ternary
[on_true] if [expression or condition] else [on_false]
- Expression is a set of variables, operators, and functions that can be evaluated according to the syntax of the language.
All data types built into Python are divided into:
- Immutable - numbers, strings, tuples, boolean.
- Mutable - dictionaries, lists, sets, and virtually all other types.
There are 3 types of numbers in Python:
- Integers (int).
- Decimal numbers (float).
- Complex numbers are a pair of integers, the first of which is called the real part, and the second is called the imaginary part.
Operations performed on numbers:
"+" is the addition of two numbers.
"-" - subtraction.
" * " - multiplication.
" ** " - exponentiation.
"/" - true division.
"//" - quotient.
"%" is the remainder of the division.
" - " - unary minus.
"abs" are the number module.
PEP - Python Enhancement Proposals.
PEP-8 is a set of rules on how to write code.
PEP-257 standard flow for docstrings
Python is not named after a snake
Python creator - Guido van Rossum
and he named his language after the Monty Python troupe.
21