Tribalyte Technologies Tribalyte Technologies
  • Home
  • Mission & Vision
  • Our experts
  • Our software solutions
  • Business cases
  • Blog
  • Contact us
  • Español
Tribalyte Technologies Tribalyte Technologies
  • Home
  • Mission & Vision
  • Our experts
  • Our software solutions
  • Business cases
  • Blog
  • Contact us
  • Español
Dec 08

Introduction to Python

  • December 8, 2018
  • Lucie Wu
  • No Comments
  • Uncategorized

“Life is short (you need Python)” comes from Bruce Eckel’ s blog signature.
If you’ve heard of the TIOBE leaderboard, you’ll know the popularity of programming languages.
This is a variation of the most 10 commonly used programming languages over the past 10 years:

imagen 1

Today, we will introduce some basic knowledge of this forth popular programming language——Python.

1. What is Python

Python, like Java and C#, is also a virtual machine-based language. When we type “hello.py” on the command line, actually we activate the Python “interpreter” and tell the “interpreter” that “you” will start working. However, before the “interpretation”, the first work performed is the same as the compiled Java. So we should describe Python in this way: Python is a language that is first compiled and then interpreted.

2. Running process of Python

Before we discuss that, let’s learn about two concepts, PyCodeObject and pyc files. We may already know about the pyc on the hard disk, PyCodeObject is actually the result of the Python compiler. When the Python program runs, the compilation results are stored in PyCodeObject in memory. After the running finished, the Python interpreter writes PyCodeObject back to the pyc file. As it runs for the second time, the program will first look for the pyc file on the hard disk. If found, it will be loaded directly, otherwise the above process will be repeated.
Therefore, we say that the pyc file is actually a persistent save of PyCodeObject.

3. The functions of Python

Now let’s know more about Python through its functions.

3.1 Function format

The function format of Python is as follow:

imagen 2

Note: The statement following the indentation of the function is called a statement block. Indentation is for the logic and affiliation of the table name statement. It can not be ignored, otherwise the code can not run successfully.

3.2 Parameters

3.2.1 Positional arguments

For example,

imagen 3

 

 

Then we call this function:

imagen 4

 

Obviously,the filled parameters 1, 2, and 3 correspond to the parameters base_up, base_down, and height, respectively. This way of passing parameters is called positional arguments.

3.2.2 Keyword arguments
When calling a function, we assign a value to each parameter name. For example, when we call function fun1:

imagen 5

Output:

imagen 6

3.2.3 Variable-length arguments

Sometimes when designing a function interface, we are not able to determine the number of parameters passed in beforehand. Python provides a way to accept parameters that are not directly defined through adding an asterisk * to the front of the parameter. If no argument is specified when the function is called, it is an empty tuple. We can also pass unnamed variables to functions. For example:

imagen 7

From the output, we can see that * hobby is a variable parameter, and hobby is actually a tuple.

 

3.2.4 Keyword-only arguments

This can be achieved by placing the keyword-only arguments inside a * parameter or a single *, for example :

imagen 9

3. 3 Anonymous function

Python uses lambda to create anonymous functions, that is, no longer define a function in the standard form of a def statement.

Basic syntax:

imagen 12
For example:

imagen 11

 

 

 

4. The shortcomings of Python

4.1 Low operating efficiency

The main drawback of Python is : slow. It runs slower than C, C++, and Java. This is mainly because Pyhton is an interpreted language that must be interpreted before when the program is run.

4.2 Unable encryption

Python relies on indentation to write codes, which can’t be compressed and confused. So it also determines that Python codes can’t be encrypted.

And with this ends another interesting entry in our blog, if you have any questions or suggestions for us to write about a specific topic do not hesitate to contact us at: blog@tribalyte.com

  • Facebook
  • Twitter
  • LinkedIn
  • E-Mail

About The Author

Lucie wu is a software engineer at Tribalyte, also with a mathematical finance background. She is engaged in software development and blockchain based on TypeScript, Angular and lonic. Combining economy and technology is her pursuit.

Leave a reply Cancel reply

Your email address will not be published. Required fields are marked *

A company dedicated to developing and improving global tech platforms.

Contact

Glorieta de Quevedo 8 6º2
28015 Madrid (ESPAÑA)
Phone: +34 919 049 820 E-Mail: contact@tribalyte.com Web: www.tribalyte.com
Sello PYME INNOVADORA 21/01/2025
PYME INNOVADORA
Válido hasta el 21 de enero de 2025
escudo de MEIC 21/01/2025

HELP

  • Privacy policy
  • Quality Policy
  • Terms of use

CERTIFICATIONS

⠀⠀⠀⠀⠀⠀⠀⠀⠀

Internationalization

Tribalyte Technologies S.L. has obtained aid C007/20-ED from Red.es to drive and promote R&I activities and to encourage business investment to develop the iPatia project. Likewise, we highly value the contribution of the ERDF, the leading fund of the European cohesion policy, for what it means to boost our work and consequently to economic growth and job creation in this region and Spain as a whole.
This website uses cookies to improve your user experience and gather anonymous usage statistics. Accept More information