Expressions and Statements in Python
A statement is an execution unit, while an expression is an evaluation unit. Simply put, everything that returns a value in Python is an expression. Understanding this will help you create clearer and cleaner programs.
Let's look at the following program as an example:
import platform
version = platform.python_version()
print('This is python version {}'.format(version))The first line is a statement, it does not return any value, but can be executed by itself to import platform. This means that every line of code in Python is a statement. The third line of code is both a statement (as it is a line of code) and an expression since we are assigning a value to a variable. Finally, the last line is also an expression since although we are not explicitly assigning the value of a function, the function itself is returning a value.
Categories
- Laravel
- Sublime Text
- OpenSSL
- PHPUnit
- Go
- Apache
- Docker
- MySQL
- OWASP
- SOLID
- JOSE
- PostgreSQL
- Static Code Analysis
- SSH
- Digital Ocean
- Java
- Javascript
- GNU/Linux Debian
- PHP
- POO
- Lenguaje C
- Lenguaje C++
- RegExp
- HTML
- Vue.js
- HTTP
- Redis
- Supervisor
- Buenas prácticas
- Ubuntu
- Webpack
- Vim
- Linux
- Arch Linux
- CSS
- Flutter
- Laravel Vapor
- CI/CD
- cPanel
- WHM
- Networking
- Python
- MacOS
- Lógica y algoritmia
- Git
- Dart
- AWS
- Codeception
- Visual Studio Code
- TypeScript
- SEO
- Node.js
- Nuxt.js
- Google Cloud
- React