Python Introduction
Python is dynamically typed (because it doesn't use explicit datatype declarations) and strongly typed (because once a variable has a datatype, it actually matters) language. Let's understand each of these concepts in detail.
Statically typed language
It is a language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages. Python is not.
Dynamically typed language
It is a language in which types are discovered at execution time; the opposite of statically typed. VBScript and Python are dynamically typed , because they figure out what type a variable is when you first assign it a value.
Strongly typed language
It is a language in which types are always enforced. C, Java and Python are strongly typed. If you have an integer, you can't treat it like a string without explicitly converting it.
Weakly typed language
A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as the integer 123, all without any explicit conversion.
Salient Features of Python
- Interpreted language (no extra time for compilation, linking). Very useful at the development phase.
- Python programs are platform independent. Same python script can be run in different OS (windows/linux/mac)
- Simple to use, but it is a real life programming language. à much more support for large programs than shell, perl etc
- Python is Object Oriented Language - Useful for larger projects.
- Error handling (much more than C language)
- Splits your program into modules (Can be reused)
- A large collection of standard libraries (I/O, system calls, sockets, database, graphic UI etc)
- Python program is much shorter than equivalent C, C++, or Java programs
- Portable and Extensible. Can easily extend c/c++ programs into python library
- Easy to Learn and easy to Maintain
Installation
On modern Linux distributions, you are likely to find Python already installed. It may be a few versions behind, but should work just fine for most of the topics covered in this book. To get the exact version used here, visit the Python downloads page and install using the appropriate source for your operating system.
Using the installer from the downloads page is the easiest option to get started on Windows and macOS. See docs.python: Python Setup and Usage for more information.
For Linux, check your distribution repository first. You can also build it from source as shown below for Debian-like distributions:
$ wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tar.xz
$ tar -Jxf Python-3.13.0.tar.xz
$ cd Python-3.13.0
$ ./configure --enable-optimizations
$ make
$ sudo make altinstall
Online tools
In case you are facing installation issues, or do not want to (or cannot) install Python on your computer for some reason, you can use Open Editor — MyWhiteBoard's in-browser Python runner. Pick a language, write or edit code, provide input, and run it instantly without installing anything on your own machine.
Watch out: Open Editor demo walks through importing a sample program, modifying it to take user input, and running it to see the result.
First program
# welcome.py
print('*************')
print('Welcome to Python programming!')
print('*************')
If you are familiar with using the command line on a Unix-like system, run the script as shown below (use py welcome.py if you are using Windows CMD). Other options to execute a Python program will be discussed in the next section.
$ python3.13 welcome.py
*************
Welcome to Python programming!
*************
Try it in Open Editor
A few things to note here. The first line is a comment, used here to show the name of the Python program. print() is a built-in function, which can be used without having to load some library. A single string argument has been used for each of the three invocations. print() automatically appends a newline character by default. The program ran without a compilation step. As quoted earlier, Python is an interpreted language. More details will be discussed in later chapters.