Getting Started | Basics

Table of contents

  1. Python Course-Part 01-Getting Started with Python| Development environment
  2. Python Course-Part 02-Getting Started with Python| Basics
  3. Python Course-Part 03-Data Types | Data Structures
  4. Python Course-Part 04-Control Structures
  5. Python Course-Part 05-Functions
  6. Python Course-Part 06-Database Access

1. Modules and Packages

In the Python Course-Part 01 Getting Started with Python| Development Environment different environments to write Python code, like Jupyter Notebook, have been introduced. Independent of the used environment there are some basic functions, which are directly available. In the Python standard library are many functions, which are defined in modules.

1.1 Install and download external packages

External Python packages are available from the software repository Python Package Index (PyPI). The application pip is the package manager of PyPI. It can be launched from the command line. You can download, install, update or remove packages.

pip install package_name
pip search package_name
pip show package_name
pip uninstall package_name
CMD Windows(Command-Line-Interpreter)

1.2 Conda

If Anaconda is installed, the included conda package manager can be applied as an alternative to the pip package manager. The available packages are listed on the Anaconda package list.

conda install package_name
Anaconda Navigator

1.3 Import of packages an modules

All installed packages can imported by: import package_name. For example to import the time package of the Python standard library:

import time
help(time)
help function
time.ctime()
packages all functions

1.4 Print

The value of a variable can be printed by print(variable_name)

5 divided by 2.000000 is 2.500
2.000000 divided by 5 is 0.400

1.5 Input

Python programs may require input of users. For this the input() function can be applied.

-------------------------------------------------------------------------------------------------------
Float Input 1: 1.5
Float Input 2: 2.0
-------------------------------------------------------------------------------------------------------
Input 1: 1.5 | Input 2: 2.0
1.5 * 2.0 = 3.0

1.6 Read from file

In Python input from files and output to files is realized by file objects. A file object is returned by the function open(filename,mode), where the string-variable filename defines the name of the file that shall be accessed, and the string variable mode defines how the file shall be accessed.

mode = 'w' for writing to a file (if the file already exists it will first be erased)
mode = 'a' for appending to a file
mode = 'r' for reading from a file
mode = 'r+' for reading from and writing to a file

1.7 Write to file

Writing to files can be done in 2 different modes:

- mode='w': if the file shall always be erased before writing new text to it
- mode='a': if the new content shall be appended to the already available contents in the file

Data Analyst

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store