Zone of Development

by Damiano Abballe

Category: Python

Python – Try/Except

In this post, we will see how to manage Try/Except in Python. Just to remember what try/except is: Try/Except is a statement marks a block of statements to try and specifies a response should an exception be thrown.In detail, in Try/Except we have three blocks:Try,  used to test a block of code for errors.Except, used […]

Read More

Python – Eval

In this post, we will see what Eval() is and how we can use it. We start creating a function that returns true if a given inequality expression is correct and false otherwise. Examples: test_signs(“3 < 7 <11”) return Truetest_signs(“13 > 44 > 33 > 1”) return Falsetest_signs(“1 < 2 < 6 < 9 > […]

Read More

Python – Challenge: FizzBuzz

In this post, we will see how to resolve FizzBuzz using Python.We will create a function that takes a number as input and it will return “Fizz“, “Buzz” or “FizzBuzz“.The rules are: If the number is a multiple of 3 the output should be “Fizz”. If the number is a multiple of 5, the output should […]

Read More

Python – How to connect to MySQL

In this post, we will see how to connect a Python application with the MySQL Db called “DbManagerUser”, created in the post: MySQL – How to create a DB. First of all, in order to install the MySQL connector for Python, we run the command pip install mysql-connector-python. Then, we open Visual Studio Code and […]

Read More

Python – How to create a RESTful service

In this post, we will see how to create a RESTful service for handling data of some Dogs, with Python and Flask. First of all, what Flask is?From Wikipedia:“Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.It has no database abstraction layer, form validation, or any […]

Read More

Python – How to connect to SQL Server

In this post, we will see how to connect Python to SQL Server. First of all, we create a database called DBTestPython and then, we run some sql scripts in order to create two tables and feeding them with some test data: TABTYPE: TABUSER: FEED DATA: Now, in order to connect Python to a Sql […]

Read More

Python – How to call a RESTful Web service

In this post, we will see how to call and use a web service with Python. First of all, we need to install a library called “request“, in order to make a HTTP request from python script.This library isn’t part of the standard Python library thus we need to install it, using the command pip3 […]

Read More

Python – How to read and write a text file

In this post, we will see how to read and write a text file with Python. First of all, we create a Text file called testpython.txt and write inside these five rows: READ A FILE:We create a file called readfile.py: [readfile.py] If we run the file, using the command python3 readfile.py, this will be the […]

Read More

Python – Set

Set is an unordered collection of comma separated elements inside curly braces. The order of element is undefined and it is possible to add and delete elements and, it is possible to perform standard operations on sets like union, intersection and difference.In this post, we will see how to manage Set in Python. CREATE: ADD: […]

Read More

Python – Tuple

A tuple is a collection of immutable objects, separated by commas.In this post, we will see how to manage Tuples in Python. CREATE A TUPLE: CONCATENATION: NESTING: GET VALUES: DELETE A TUPLE: UPDATE: TUPLE IN ACTION:

Read More