Introduction to Python
One of the many languages preferred by AI programmers worldwide is Python, conceived by Guido van Rossum. It's an interpreted, interactive, object-oriented programming language that incorporates classes, modules, and high-level dynamic data types.
Python syntax is clear and leaves no room for ambiguity. As such, it facilitates clear understanding and readability of program code. It supports a variety of features and is extendable in C or C++, meaning it has access to a large library of standard and customized functions.
Python: Basic syntax
Python is a high-level programming language which is interpreted. This means the written code isn't converted into machine language to be executed on the computer directly but creates a pseudo-code which is read and executed by an interpreter which acts as a go-between between the pseudo-code and the computer.
Other such interpreted languages include BASIC, PHP, Perl, Ruby, and others.
Python: Variable types
There are five standard data types used in Python to store information. For example, a person's age could be stored as a NUMBER or a STRING, and a simple contact database could be stored as a LIST. Data types define the type of data, what operations can be performed on them, and the data type of any output.
The Data types are:
- Number
- Dictionary
- String
- Tuple
- List
Assigning values to variables
Python variables don't need explicit declaration to reserve memory space. This happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.
The operand to the left of the ‘=‘ operator is variable name and the operand to the right of the ‘=‘ operator is the value stored to be assigned to the variable.
Examples
- One = 1 Assigns the numeric value 1 to a variable called One
- One = “1” Assigns the text string “1” to a variable called One
These examples are different from each other as one data type is a NUMBER and the other a STRING.
Python: Decision making
Decision making is the anticipation of conditions occurring during execution of a program and specifying the actions to be taken according to the conditions met. Decision structures evaluate multiple expressions which produce a result as TRUE or FALSE. The programmer determines which action to take and therefore which statements to execute if outcome is TRUE or FALSE.
- Python defines non-zero and non-null values as TRUE, and zero or null values as FALSE.
FSCTECH gives five reasons to learn Python in this video.